2016-09-14 116 views
0

我試圖設置nginx,所以每個路徑都有自己的根目錄。這是工作的大部分,但是POST到PHP-FPM一個扔一個405nginx每個子目錄有一個獨立的根目錄

目前正在努力:

location ^~ /foo { 
     alias /www/foo; 
     #index index.php; 
     try_files $uri /www/foo/index.php$request_uri; 
     access_log /var/log/nginx/foo.log main; 
     error_log /var/log/nginx/foo.log error; 
    } 

    location ^~ /bar { 
     alias /www/bar; 
     #index index.php; 
     try_files $uri /www2/bar/index.php$request_uri; 
     access_log /var/log/nginx/bar.log main; 
     error_log /var/log/nginx/bar.log error; 
    } 

    location ~ \.php { 
     set $php_root /usr/local/deploy/baz/current/web; 
     if ($request_uri ~* /foo) { 
      set $php_root /www/foo/current/web; 
     } 
     if ($request_uri ~* /bar) { 
      set $php_root /www2/bar/current/web; 
     } 

     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name; 
     fastcgi_param DOCUMENT_ROOT $php_root; 
     include  fastcgi_params; 
} 
+0

是否*任何* POST請求到php-fpm拋出405錯誤?如果不是,請說明 – YakovL

回答

0

別名沒有位置路徑追加到該文件的路徑。檢查邏輯流程。如果服務器根位於/var/www/publicfoo位於/var/www/foo/publicbar位於/var/www/bar/public。那麼,這將是很容易配置:

server { 
root /var/www/public; 
... 
location /foo { 
    root /var/www/foo/public; 
    } 
location ~ /foo/.+\.php$ { 
    fastcgi_param SCRIPT_FILENAME /var/www/foo/public$fastcgi_script_name; 
    # rest of fastcgi 
} 

location /bar { 
    root /var/www/bar/public; 
} 

location ~ /bar/.+\.php$ { 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_param  SCRIPT_FILENAME/var/www/bar/public$fastcgi_script_name; 
    # rest of fastcgi 
} 
} # ends server 

如果你想在一個指令即可使用PHP:

用法
server { 
... 
root /var/www/public; 
... 
location /foo { 
    root /var/www/foo/public; 
    } 
location /bar { 
    root /var/www/bar/public; 
    } 

location ~ \.php$ { 
    set $php_root /var/www/public; 
    if ($request_uri ~* /foo) { 
     set $php_root /var/www/foo/public; 
    } 
    if ($request_uri ~* /bar) { 
     set $php_root /var/www/bar/public; 
    } 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name; 
    include /etc/nginx/fastcgi_params; 
     } 
... 
} # server block ends 

alias - http://nginx.org/en/docs/http/ngx_http_core_module.html#alias Nginx的改性劑 - http://nginx.org/en/docs/http/ngx_http_core_module.html#location

如果你需要更多的路徑,那麼你必須符號鏈接。