Come configurare Nginx per eseguire PHP

Oct 04 2020

Questa è la configurazione di 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;

         } 

    }

Ma quando sono in esecuzione su 127.0.0.1:9000 non funziona. Su localhost mostra 403 Forbidden. Come puoi vedere, ho cancellato le righe commentate.

Risposte

1 user969068 Oct 04 2020 at 21:47

Dovresti sempre usare $document_rootinvece fornendo il percorso di root ovunque

fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

E controlla se il tuo processo php-fpm è in esecuzione, ad esempio se stai usando systemctl run

systemctl status php-fpm
systemctl start php-fpm

controlla anche se stai usando lo stesso percorso fast_cgi, dovrebbe corrispondere in www.conf del file php-fpm (potrebbe essere qui /etc/php-fpm.d/www.conf)

listen = 127.0.0.1:9000

e il file di configurazione del sito nginx.conf

fastcgi_pass 127.0.0.1:9000;

dopo aver aggiornato i file, riavvia i servizi Nginx / php-fpm.

e poi visita http: // localhost (come hai impostato nome_server sopra) nel tuo browser, non 127.0.0.1:9000.