suchen

Heim  >  Fragen und Antworten  >  Hauptteil

nginx php-fpm 都已经设置好,访问php页面直接下载文件

    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文件,头都大了,不知道为什么。 
   
PHPzPHPz2864 Tage vor757

Antworte allen(8)Ich werde antworten

  • 漂亮男人

    漂亮男人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...

    Antwort
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:12:34

    fastcgi_pass 0.0.0.0:9000; 0.0.0.0是什么鬼

    Antwort
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:12:34

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

    Antwort
    0
  • PHPz

    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/$1 last;    
        }
    
        location ~ [^/]\.php(/|$) {
            fastcgi_pass  127.0.0.1:9000;
            include fastcgi.conf;
        }
    
        access_log  /Users/zhgxun/Public/html/logs/frontend.log  main;
    }

    我本地使用的配置。

    Antwort
    0
  • PHP中文网

    PHP中文网2017-05-16 13:12:34

    php-fpm 重启否?

    Antwort
    0
  • 習慣沉默

    習慣沉默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=/$1 last;
            rewrite ^/(.*) /index.php?$1 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;
                   }  
         }

    参考一下我的试一试

    Antwort
    0
  • 为情所困

    为情所困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

    Antwort
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:12:34

    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 改成这句,从0.8我用nginx起就一直用这句。

    Antwort
    0
  • StornierenAntwort