我有一个应用程序正在运行在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”目录下创建一个“current”目录,用于存放从Github拉取的应用程序文件,因此我需要将根路径更改为:
/home/deployer/apps/modules/foo/current/
但是Nginx将location指令追加到根指令的末尾...因此,当您访问/foo时,Nginx会尝试查找:
/home/deployer/apps/modules/foo/current/foo/
使用别名应该忽略在位置指令中设置的/foo,并从确切的别名路径提供文件(日志证实正在发生),但是当我使用别名指令时,php配置无法正确应用,我收到了404错误。
如果我回到根指令并完全删除“current”目录,则可以正常工作。我需要从“current”目录提供文件以使Capistrano部署平稳进行,但无法弄清如何将别名指令与php配合使用。
有人有任何想法或建议吗?我是否漏掉了什么?
fastcgi_param SCRIPT_FILENAME
和它设置在fastcgi_params
或fastcgi.conf
中的事实,请参见此处和此处。 - hrvoj3e