我有一个全新安装的Ubuntu 14.04服务器.我已经安装了nginx,php等….
server {
listen 80;
listen [::]:80;
server_name testone.local;
root /var/www/htmlone;
index index.html;
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php${
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /alias {
alias /var/www/htmlalias;
location ~ \.php${
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
如果我在/ var / www / htmlone中使用一个简单的php脚本php按预期执行.如果我在/ var / www / htmlalias中使用相同的脚本,它不会按预期执行.如果我在/ var / www / htmlalias中放置一个HTML脚本,它会按预期显示,所以别名充当别名,但不执行php文件,但php在主根目录中工作.
我在许多服务器故障问题上发现这个常规设置应该可以工作但事实并非如此.有没有人看到我可能做错的事情?我在错误日志中看不到任何消息.
我应该添加这是针对nginx版本:nginx / 1.8.0
最佳答案
您遇到的问题实际上是long-standing bug that was filed 3 years ago,导致别名和try_files无法真正协同工作.
在错误页面上有一个workaround by Luke Howell,如下所示:
location /api { ## URL string to use for api ##
alias /home/api/site_files/; ## Site root for api code ##
## Check for file existing and if there,stop ##
if (-f $request_filename) {
break;
}
## Check for file existing and if there,stop ##
if (-d $request_filename) {
break;
}
## If we get here then there is no file or directory matching request_filename ##
rewrite (.*) /api/index.php?$query_string;
## Normal php block for processing ##
location ~ \.php${
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
请注意,就nginx而言,IF is evil and should be avoided if possible.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。