Nginx Zend框架和静态内容错误

Nginx Zend框架和静态内容错误,nginx,zend-framework2,Nginx,Zend Framework2,以下是相关的nginx配置(这不是一个纯ZF应用程序,而是嵌入了ZF) http://example.com/interface/modules/zend_modules/public/Installer成功返回页面,但CSS、JS和所有图像返回404 我就是不知道如何让我的静态内容不被重定向到index.php(静态内容位于../zend_modules/public/(css | js | images)第一个位置块的工作方式与您期望的不一样。它只是将URI重写为/interface/mod

以下是相关的nginx配置(这不是一个纯ZF应用程序,而是嵌入了ZF)

http://example.com/interface/modules/zend_modules/public/Installer
成功返回页面,但CSS、JS和所有图像返回404


我就是不知道如何让我的静态内容不被重定向到
index.php
(静态内容位于
../zend_modules/public/(css | js | images)

第一个位置块的工作方式与您期望的不一样。它只是将URI重写为
/interface/modules/zend\u modules/public/index.php,因为您的根
值很奇怪

对于所有
location
块,
root
的值应为
/srv/app
,因为
nginx
通过将
root
值与URI连接来构造路径名。有关详细信息,请参阅

您建议此
服务器
实现多个应用程序,因此要将这些位置限制为以
/interface/modules/zend_modules/public/
开头的URI,请使用嵌套位置并使用
^
修饰符。有关详细信息,请参阅

例如:

location ^~ /interface/modules/zend_modules/public {
    root /srv/app;

    try_files $uri $uri/ /interface/modules/zend_modules/public/index.php$is_args$args;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi.conf;
    }
}
编辑:

如果多个应用程序基于PHP,并且共享相同的
根目录
,则可以使用如下内容:

root /srv/app;

location /interface/modules/zend_modules/public {
    try_files $uri $uri/ /interface/modules/zend_modules/public/index.php$is_args$args;
}
location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi.conf;
}

..
是什么意思?它是
/srv/app/interface/modules
?还有,
css
文件的URI是什么?它是
/interface/modules/zend\u modules/public/css/foo.css
?是的,
..
只是
/srv/app/inter/inter/modules
的缩写。css的URI确实是你认为的
/inter仔细看,这实际上并不能解决我的问题。虽然这确实解决了该页面上的ZF索引重定向和静态内容,但所有其他脚本都解决了该页面上的ZF索引重定向和静态内容位于interface/modules/zend_modules/public外部的现在返回404。例如,
interface/library/otherfile.php
返回404。
服务器
仅为这一个应用程序提供服务(很抱歉出现任何混乱)您可以将
放在
位置
块中,但通常允许继承
的公共值。修改后的答案允许其他应用程序共享
位置~\.php$
块(与您最初使用的一样)。已解决(这次是真的)
root /srv/app;

location /interface/modules/zend_modules/public {
    try_files $uri $uri/ /interface/modules/zend_modules/public/index.php$is_args$args;
}
location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi.conf;
}