nginx php,在根目录中带有WordPress,在子目录中有另一个应用程序


nginx php with wordpress at root and another app in subdirectory

我在让子目录在我的nginx服务器上工作时遇到了一些问题。

我正在使用nginx将wordpress安装作为Web根目录,并尝试在子目录中运行额外的php应用程序。 WordPress运行良好,但是对于各种配置的错误,我一生都无法让应用程序在子目录中运行,而无需404,403或"未指定输入文件"。 我确定有一些明显的东西,但我似乎想不通!

以下是相关的配置:

任何帮助将不胜感激!

server {
listen       myserver.edu:8081;                
server_name  myserver.edu:8081;           
try_files $uri $uri/ /index.php;

location / {
    root /path/to/nginx/html/wordpress;
    index index.php;
}
location /stacks {
    alias /another/path/to/usr/local/share/stacks/php;
    index index.php;
}
location ~ '.php$ {
    set $php_root /path/to/nginx/html/wordpress;
    include        fastcgi_params;
    fastcgi_pass   localhost:8082;
    fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
    }
location ~ 'stacks.php$ {
    set $php_root /another/path/to/usr/local/share/stacks/php;
    include        fastcgi_params;
    fastcgi_pass   localhost:8082;
    fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
    }
我不知道

如何使用您的别名并设置 $php_root 来做到这一点。 如果您将符号链接从外部文件夹链接到wordpress-rootdirectory,我确实知道如何修复它。

因此,使用终端,您可以创建一个符号链接,以便您的stacks-subdirectory是一个实际的子目录:

 ln -s /another/path/to/usr/local/share/stacks/php /path/to/nginx/html/wordpress/stacks

作为nginx配置,我会使用

server {
    listen       myserver.edu:8081;                
    server_name  myserver.edu:8081;
    root /path/to/nginx/html/wordpress;
    index index.php;       
    location / {    
        try_files $uri $uri/ /index.php;
    }
    location /stacks {
        try_files $uri $uri/ /stacks/index.php;
    }
    location ~ '.php$ {
        fastcgi_pass   localhost:8082;
        include        fastcgi_params;
    }
}
注释

掉"try_files"。那么子目录开始工作了吗?也许它是在考虑"位置"指令之前处理的。如果是这种情况,则将"try_files"移动到"位置/"块中。

我认为无论如何,这是"try_files"的更好地方。在当前配置中,看起来对不存在的文件的请求都将发送到Wordpress,即使它们位于"堆栈"目录中。