nginx php-fpm 都已经设置好,访问php页面直接下载文件
PHPz
PHPz 2017-05-16 13:10:34
0
8
748
    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文件,头都大了,不知道为什么。 
   
PHPz
PHPz

学习是最好的投资!

全部回复(8)
漂亮男人

应该是把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...

我想大声告诉你

fastcgi_pass 0.0.0.0:9000; 0.0.0.0是什么鬼

phpcn_u1582

如果是新手的话, 不建议自己配置, 尽量使用一键配置比如:https://lnmp.org的lnmp一键安装

PHPzhong
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;
}

我本地使用的配置。

洪涛

php-fpm 重启否?

習慣沉默
        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;
               }  
     }

参考一下我的试一试

为情所困

建议查看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

巴扎黑

雷雷

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板