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;
}
With this setting, accessing the php page will directly download the php file.
But don't redirect
location/{
index index.php
}
I can execute the php file normally, but my head is spinning and I don’t know why.
漂亮男人2017-05-16 13:12:34
You should just change break to last
location / {
rewrite ^/ /index.php break;
}
What you mean is to rewrite all uri forwarding requests to index.php and then break. The new rewritten uri (rewritten to index.php in this example) will no longer match the following location. , so your php file is not passed to php-fpm for parsing. But after changing to last, the new uri will re-match the location that meets the conditions, so index.php is passed to php-fpm for parsing and execution.
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;
}
If you don’t understand, please recommend one of your own blogs. http://blog.csdn.net/fantexi1...
phpcn_u15822017-05-16 13:12:34
If you are a novice, it is not recommended to configure it yourself. Try to use one-click configuration such as: https://lnmp.org's lnmp one-click installation
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;
}
The configuration I use locally.
習慣沉默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;
}
}
Please refer to mine and give it a try
为情所困2017-05-16 13:12:34
It is recommended to check the logs of nginx and php to find the problem,
My conf is like this:
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;
}
Also, is your php-fpm process normal?
$ 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
巴扎黑2017-05-16 13:12:34
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 改成这句,从0.8我用nginx起就一直用这句。