How to Configure Nginx to Execute PHP

情到浓时终转凉″ 提交于 2021-01-28 11:45:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/64193525/how-to-configure-nginx-to-execute-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!