今天在一個新的服務器上部署網站,訪問php文件,居然出現404
服務器是騰訊雲的免費的服務器
Centos 7.2 + php7.1.7 + nginx1.12.1
安裝的是lnmp一鍵安裝包,沒有使用編譯的方式安裝。
安裝完後,添加配置文件在 /usr/local/nginx/conf/vhost
配置文件內容以下:php
server { listen 80; root /home/wwwroot/site; index index.php index.html index.htm; #charset koi8-r; access_log /home/wwwlogs/site.access.log main; error_log /home/wwwlogs/site.error.log warn; # 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; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php($|/) { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_read_timeout 150; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; } }
這個配置,通常來講都是沒有問題的,而後就執行下面的命令重啓nginxhtml
service nginx restart
而後訪問 我放在網站根目錄的php文件,提示404,nginx
這我就鬱悶了,文件明顯存在啊,怎麼會找不到呢!難道根目錄設置錯了?
就在根目錄放了個html文件,訪問一下,200,能夠訪問!
那麼這問題就明顯了,這應該是配置文件中 php的問題!或者說是 php-fpm的問題
可是我沒有配置錯誤日誌,我先在配置文件中配置錯誤日誌,測試一下,看看報錯!
看到報錯,我驚呆了!請看下面:服務器
[error] 32520#0: *1 open() "/usr/share/nginx/html/50x.html" failed (2: No such file or directory)
怎麼會這樣,原來應該爆500錯誤的,可是找不到50x.html文件,就爆了404錯誤。php7
那我添加上這個 50x.html 文件,訪問後,顯示了這個50x.html 文件,而後查看錯誤日誌顯示以下:php-fpm
[error] 344#0: *1 connect() failed (111: Connection refused) while connecting to upstream,
連接失敗?怎麼會?測試
這裏的連接應該是 nginx配置文件中配置的連接 php-fpm的配置連接,配置文件應該是沒問題的,那就查看下php-fpm是否已經啓動!網站
ps -aux | grep php
顯示正常,如圖:spa
說明php-fpm已經啓動,就查看了下 9000端口是否已經開啓:3d
netstat -ant | grep 9000
沒有輸出,也就是說,9000端口沒有開啓,也就是會所php-fpm沒有佔用900端口
而後查看php-fpm.conf,查看其中 代碼,如圖:
看到這,問題就很明顯了,就是沒有偵聽9000端口啊,那麼nginx配置中偵聽的9000固然會失敗
這裏只須要修改下這句話就好了,以下:
listen = 9000
而後執行命令
service nginx restart
重啓nginx
service php-fpm restart
重啓 php-fpm
測試看看,一切OK!,再也不報錯!