我想将使用Zend Framework 2的站点从Apache移动到Nginx。 问题是该站点有6个模块,并且apache通过在httpd-vhosts.conf中定义的别名来处理它,
#httpd-vhosts.conf <VirtualHost _default_:443> ServerName localhost:443 Alias /develop/cpanel "C:/webapps/develop/mil_catele_cp/public" Alias /develop/docs/tech "C:/webapps/develop/mil_catele_tech_docs/public" Alias /develop/docs "C:/webapps/develop/mil_catele_docs/public" Alias /develop/auth "C:/webapps/develop/mil_catele_auth/public" Alias /develop "C:/webapps/develop/mil_web_dicom_viewer/public" DocumentRoot "C:/webapps/mil_catele_homepage" </VirtualHost>
在httpd.conf中DocumentRoot被设置为C:/ webapps。 例如localhost/develop/cpanel站点。 框架处理更多的路由。
在Nginx中,我只能通过指定root C:/webapps/develop/mil_catele_tech_docs/public; 在服务器块。 它的工作原理只是因为docs模块不像其他人那样依赖auth,而且site是在localhost/ 。
在下一次尝试中:
root C:/webapps; location /develop/auth { root C:/webapps/develop/mil_catele_auth/public; try_files $uri $uri/ /develop/mil_catele_auth/public/index.php$is_args$args; }
现在,当我进入localhost/develop/cpanel它得到正确的index.php,但无法find任何资源(CSS,JS文件)。 我不知道为什么浏览器的GET请求中的引用path更改为https://localhost/css/bootstrap.cssformshttps://localhost/develop/auth/css/bootstrap.css因为它在apache上。 这根指令似乎不工作。
Nginx使用fastCGI处理php
location ~ \.(php|phtml)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param APPLICATION_ENV production; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
我search了一整天,没有发现有用的东西。 有人可以帮助我使这个configuration在Apache上工作吗?
你不应该在location块内使用root指令。
尝试这个:
location /develop/auth { alias C:/webapps/develop/mil_catele_auth/public; try_files $uri $uri/ /index.php$is_args$args; }
有了这个configuration,URL就像这样工作:
http://example.com/develop/auth/image.png – > C:/webapps/develop/mil_catele_auth/public/image.png
如果你使用root而不是alias ,你会得到:
C:/webapps/develop/mil_catele_auth/public/develop/auth/image.png 。
然后,对于一些不存在的文件/目录:
http://example.com/develop/auth/not-existing – >将运行C:/webapps/develop/mil_catele_auth/public/index.php 。
希望这样的工作方式,你希望它的工作。