我有一个在Nginx上运行的应用程序,其工作服务器块如下:
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一起工作.
任何人有任何想法或建议,我错过了什么?