![](/img/trans.png)
[英]nginx php with wordpress at root and another app in subdirectory
[英]nginx with a separate root per subdirectory
我正在嘗試設置nginx,以便每個路徑都有它自己的根目錄。 這在大多數情況下都有效,但是POST到php-fpm拋出405。
目前正在嘗試:
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;
}
別名不會將位置路徑附加到文件路徑。 檢查邏輯流程。 如果服務器根目錄位於/var/www/public
,則foo
位於/var/www/foo/public
, bar
位於/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
使用alias
: //nginx.org/en/docs/http/ngx_http_core_module.html#alias Nginx修飾符-http://nginx.org/en/docs/http/ngx_http_core_module.html#location
如果您需要更多數量的路徑,則必須進行符號鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.