無法運行配置 PHP

無法運行配置 PHP

我已經安裝了nginx1.13.1和php7.0.18,我嘗試在我的網站伺服器上執行設定PHP頁面,但出現404未找到錯誤。你能幫我看看如何配置嗎

Nginx 配置( /etc/nginx/conf.d/*.conf )如下:

server {
    listen       80;
    server_name example.com;

   # charset koi8-r;   
   # access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index index.php index.html index.htm;

    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
     location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
     #   fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    } 
}

答案1

您在配置的 PHP 部分中註解掉的那一fastcgi_pass行是讓 PHP 運作的原因。取消註解這些行,重新啟動 nginx,如果您更新該行以指向系統上的 PHP 套接字(請參閱 PHP 配置以取得正確的路徑),fastcgi_index它應該開始工作。fastcgi_pass

至於 404,請參閱/var/log/nginx/error.log並確保您root在伺服器配置中設定了 PHP 檔案實際儲存位置之外的位置 - 需要這樣做,以便 NGINX 知道在哪裡找到您的檔案。

相關內容