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連接埠的方式