0

我有 nginx 的这个配置:

server {
    listen       80;
    server_name  example.com www.example.com;

    location = / {
            root /var/www/example.com;
            index index.php;
    }

    location / {
            root   /var/www/example.com/Drupal;
            index  index.php index.html;

            if (!-f $request_filename) {
                    rewrite  ^(.*)$  /index.php?q=$1  last;
                    break;
            }

            if (!-d $request_filename) {
                    rewrite  ^(.*)$  /index.php?q=$1  last;
                    break;
            }
    }

    location ~ \.php$ {

            set $php_root /var/www/example.com/Drupal;

            if ($request_uri ~ ^/MassMail) {
                    set $php_root /var/www/example.com/MassMail;
            }

            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;

    }

我在 php 中有 2 个应用程序:

  • /var/www/example.com/MassMail 中的第一个
  • /var/www/example.com/Drupal 中的第二个(Drupal 博客)

我的服务器提供正确的两个 URL

example.com/ --> drupal 博客

example.com/MassMail --> 其他应用

但它不提供图像或 JavaScript ...(错误 404)

对于 serve img 等,我已经测试了很多这样的东西(例如......):

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
           expires         30d;
            access_log      off;
    }

可能缺少根目录,但是哪个?

4

1 回答 1

0

您的 php 认为 MassMail 安装在 / (root) 中,尝试为 staitc 文件添加第二个位置:

location ~* ^/MassMail.+.(jpg|jpeg|gif|css|png|js|ico)$ {
           expires         30d;
            access_log      off;
           root /var/www/xxx.com/MassMail;
}

配置#2

location ~* ^/(.*)/.+.(jpg|jpeg|gif|css|png|js|ico)$ {
  expires         30d;
     access_log      off;
   root /var/www/xxx.com/$1;
}

配置#3

将每个应用程序配置放在特殊文件中(MassMail 的示例):

应用程序/massmail.conf

  location ~ \.php$ {

            set $php_root /var/www/xxx.com/Drupal;

            if ($request_uri ~ ^/MassMail) {
                    set $php_root /var/www/xxx.com/MassMail;
            }

   location ~* ^/MassMail.+.(jpg|jpeg|gif|css|png|js|ico)$ {
           expires         30d;
            access_log      off;
           root /var/www/xxx.com/MassMail;
   }

nginx.conf

.....
include applications/massmail.conf;
于 2012-06-24T09:08:59.870 回答