[英]nginx with a separate root per subdirectory
I'm trying to setup nginx so each path has it's own root directory. 我正在尝试设置nginx,以便每个路径都有它自己的根目录。 This is working for the most part, however POST to php-fpm a throwing a 405. 这在大多数情况下都有效,但是POST到php-fpm抛出405。
Currently trying: 目前正在尝试:
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;
}
Alias does not append location path to the file path. 别名不会将位置路径附加到文件路径。 Check the logical flow. 检查逻辑流程。 If server root is at /var/www/public
, foo
is located at /var/www/foo/public
, bar
is located at /var/www/bar/public
. 如果服务器根目录位于/var/www/public
,则foo
位于/var/www/foo/public
, bar
位于/var/www/bar/public
。 Then, this will be the easy config : 然后,这将是简单的配置:
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
If you want to use PHP in one directive then : 如果要在一个指令中使用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
Usage of alias
-- http://nginx.org/en/docs/http/ngx_http_core_module.html#alias Nginx modifier -- http://nginx.org/en/docs/http/ngx_http_core_module.html#location 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
If you need more number of path, then you have to symlink. 如果您需要更多数量的路径,则必须进行符号链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.