简体   繁体   中英

How to Configure Nginx to Execute PHP

This is config of nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /Users/*name*/PHPSITE/standard;
            index  index.html index.htm;
            try_files $uri $uri/ /index.php;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /Users/*name*/PHPSITE/standard;
        }

        location ~ \.php$ {

            include /usr/local/etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index /index.php;
            fastcgi_param SCRIPT_FILENAME /Users/*name*/PHPSITE/standard$fastcgi_script_name;

         } 

    }

But when I'm running on 127.0.0.1:9000 it doesn't work. On localhost it shows 403 Forbidden. As you can see, I deleted commented lines.

You should always use $document_root instead providing root path everywhere

fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

And check if your php-fpm process is running, for example if you are using systemctl run

systemctl status php-fpm
systemctl start php-fpm

also check if you are using same fast_cgi path, it should match in www.conf of php-fpm file ( could be here /etc/php-fpm.d/www.conf)

listen = 127.0.0.1:9000

and your site config nginx.conf file

fastcgi_pass 127.0.0.1:9000;

after updating files restart your Nginx/php-fpm services.

and than visit http://localhost (as you set server_name above) in your browser , not 127.0.0.1:9000.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM