location ~ \.php$ {
fastcgi_pass 0.0.0.0:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
break;
}
location / {
rewrite ^/ /index.php break;
}
这样设置 访问php页面会直接下载php文件
但是不重定向
location / {
index index.php
}
就能够正常执行php文件,头都大了,不知道为什么。
漂亮男人2017-05-16 13:12:34
应该是把break改成last就好了
location / {
rewrite ^/ /index.php break;
}
你的这一段意思为,将所有的uri转发请求重写为index.php 然后break,新的重写后的uri(在这个列子被重写为index.php)不会再去匹配下面这个location,所以你的php文件没有传递给php-fpm去解析。但是换成last以后,新的uri会重新匹配符合条件的location,所以index.php被传递给php-fpm解析执行了。
location ~ \.php$ {
fastcgi_pass 0.0.0.0:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
break;
}
如果不明白,毛遂自荐自己的一篇博客。http://blog.csdn.net/fantexi1...
PHPz2017-05-16 13:12:34
server {
listen 80;
server_name frontend.com;
index index.html index.php;
root /Users/zhgxun/Public/html/php/zoulu/frontend/web;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/ last;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
access_log /Users/zhgxun/Public/html/logs/frontend.log main;
}
我本地使用的配置。
習慣沉默2017-05-16 13:12:34
server{
listen 80;
server_name erp.XX.xyz;
root /opt/local/www/project/xx/public;
index index.php index.html index.htm;
error_page 497 https://$host:$server_port$request_uri;
if (!-e $request_filename) {
rewrite ^(.*\.(?:css|less|scss|js|coffee|jpg|png|gif|jpeg|exe|xls|ico|xml|xlsx))$ /?sumibuy=common/munee/&files=/ last;
rewrite ^/(.*) /index.php? last;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|xml|js|css|ttf|woff|ico|exe|xls|xlsx|html)$ {
access_log off;
expires 1d;
break;
}
location ^~ /upload/{
access_log off;
expires 1d;
break;
}
location ~ .* {
fastcgi_buffer_size 128k;
fastcgi_buffers 32 32k;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/local/www/project/XX/public$fastcgi_script_name;
include fastcgi_params;
}
}
参考一下我的试一试
为情所困2017-05-16 13:12:34
建议查看nginx和php的日志来发现问题,
我的conf是这样的:
location ~* \.php5?$ {
include fastcgi_params;
##fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/usr/local/php5.6/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
另外,你的php-fpm进程正常么?
$ ps aux|grep 'php-fpm'
21274 user php-fpm: master process (/usr/local/php5.6/etc/php-fpm.conf)
21275 user php-fpm: pool www
21276 user php-fpm: pool www