網站部署 - Nginx配置PHP顯示502錯誤

來源:互聯網
上載者:User
nginx訪問沒有問題

nginx配置

server {        listen   8080;             root /opt/nginx-1.7.8/html/demo;        index index.php index.html index.htm;        server_name example.com;        location / {                try_files $uri $uri/ /index.html;        }        error_page 404 /404.html;        error_page 500 502 503 504 /50x.html;        location = /50x.html {              root /opt/nginx-1.7.8/html;        }        # pass the PHP scripts to FastCGI server listening on the php-fpm socket        location ~ \.php$ {                try_files $uri =404;                fastcgi_pass  unix:/run/php5-fpm.sock;                fastcgi_index index.php;                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                include fastcgi_params;                        }

/opt/nginx-1.7.8/html/demo目錄下遊index.php,然是訪問報錯502

An error occurred.Sorry, the page you are looking for is currently unavailable.Please try again later.If you are the system administrator of this resource then you should check the error log for details.Faithfully yours, nginx.

日誌:

2015/10/25 10:36:24 [crit] 12149#0: *1 connect() to unix:/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 219.217.226.133, server: example.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php5-fpm.sock:", host: "159.203.251.133:8080"

求助~

回複內容:

nginx訪問沒有問題

nginx配置

server {        listen   8080;             root /opt/nginx-1.7.8/html/demo;        index index.php index.html index.htm;        server_name example.com;        location / {                try_files $uri $uri/ /index.html;        }        error_page 404 /404.html;        error_page 500 502 503 504 /50x.html;        location = /50x.html {              root /opt/nginx-1.7.8/html;        }        # pass the PHP scripts to FastCGI server listening on the php-fpm socket        location ~ \.php$ {                try_files $uri =404;                fastcgi_pass  unix:/run/php5-fpm.sock;                fastcgi_index index.php;                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                include fastcgi_params;                        }

/opt/nginx-1.7.8/html/demo目錄下遊index.php,然是訪問報錯502

An error occurred.Sorry, the page you are looking for is currently unavailable.Please try again later.If you are the system administrator of this resource then you should check the error log for details.Faithfully yours, nginx.

日誌:

2015/10/25 10:36:24 [crit] 12149#0: *1 connect() to unix:/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 219.217.226.133, server: example.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php5-fpm.sock:", host: "159.203.251.133:8080"

求助~

日誌已經寫得很清楚了,是sock檔案的許可權問題,你需要讓這個sock檔案能夠被nginx使用者可寫。可以配置為666,可以配置php-fpm以nginx使用者啟動,也可以讓nginx使用者加入php-fpm的組,然後sock設成660

貼出錯誤發現是許可權問題。。。把/run/php5-fpm.sock改成777就沒問題了。。

正確的應該怎樣分配許可權

我覺得起碼得設定nginx使用者擁有該許可權

也可以考慮用php—fpm 9000連接埠的方式

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.