繁体   English   中英

nginx,每个子目录都有一个单独的根

[英]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/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使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM