search

Home  >  Q&A  >  body text

nginx php-fpm has been set up. Visit the php page to download the file directly.

 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. 
   
PHPzPHPz2861 days ago751

reply all(8)I'll reply

  • 漂亮男人

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

    reply
    0
  • 我想大声告诉你

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

    fastcgi_pass 0.0.0.0:9000; What the hell is 0.0.0.0

    reply
    0
  • phpcn_u1582

    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

    reply
    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/ 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.

    reply
    0
  • PHP中文网

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

    php-fpm Restart?

    reply
    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=/ 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

    reply
    0
  • 为情所困

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

    reply
    0
  • 巴扎黑

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

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

    reply
    0
  • Cancelreply