【发布时间】:2015-01-19 21:36:09
【问题描述】:
我有一个在 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 指令附加到 root 指令的末尾......所以,当你访问 /foo 时,Nginx 会尝试查找:
/home/deployer/apps/modules/foo/current/foo/
使用 alias 应该忽略 location 指令中设置的 /foo 并从确切的别名路径(日志确认正在发生)提供文件,但是当我使用 alias 指令时,php 配置未正确应用我得到了一个 404 的返回。
如果我返回根指令并完全删除“当前”目录,它可以正常工作。我需要从“当前”目录提供的文件才能顺利使用 Capistrano 部署,但无法弄清楚如何使别名指令与 php 一起使用。
任何人有任何想法或建议,我错过了什么吗?
【问题讨论】: