server {
listen 80;
server_name example.com;
root /home/deployer/apps/my_app/current/;
index index.PHP;
location / {
index index.PHP;
try_files $uri $uri/;
}
location ~ \.PHP${
try_files $uri =404;
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass unix:/home/deployer/apps/shared/PHP5-fpm.sock;
fastcgi_index index.PHP;
include fastcgi_params;
}
location /foo {
root /home/deployer/apps/modules/;
# tried this:
# alias /home/deployer/apps/modules/foo/;
# but PHP is not working with alias, only with root
}
}
当我访问/ foo时,Nginx在路径/ home / deployer / apps / modules / foo /中查找index.PHP文件并且它可以工作.
问题:
我使用capistrano设置了一个部署脚本,该脚本部署到foo目录:
/home/deployer/apps/modules/foo/
Capistrano在’foo’目录中创建一个’当前’目录,以包含从Github引入的应用程序文件,因此我需要将根路径更改为:
/home/deployer/apps/modules/foo/current/
但是Nginx将location指令附加到根指令的末尾….所以,当你访问/ foo时,Nginx试图查看:
/home/deployer/apps/modules/foo/current/foo/
使用别名应该忽略location指令中设置的/ foo并从确切的别名路径(日志确认正在发生)中提供文件,但是当我使用alias指令时,PHP配置没有正确应用而且我是得到404返回.
如果我回到root指令并完全删除’current’目录,它可以正常工作.我需要从’current’目录提供的文件才能顺利地与Capistrano部署一起工作,但是无法弄清楚如何使alias指令与PHP一起工作.
任何人有任何想法或建议,我错过了什么?
解决方法:
感谢@ xavier-lucas关于无法将try_files与别名一起使用的建议.
要在PHP中使用别名,我必须从原始问题中显示的PHP位置块中删除try_files指令:
try_files $uri =404;
我实际上不得不在/ foo位置重新设置PHP位置块并删除上面的行.最终看起来像这样:
location /foo {
alias /home/deployer/apps/modules/foo/;
location ~ \.PHP${
# try_files $uri =404; -- removed this line
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass unix:/home/deployer/apps/shared/PHP5-fpm.sock;
fastcgi_index index.PHP;
include fastcgi_params;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。