問題:
昨天測試並搭建lnmp架構,在測試過程中,掛載好測試環境時在瀏覽器上測試網站出現“file not found",使用命令curl時也出現”file not found",
解答:
查看百度時,很多方法指向添加fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;但是測試中不行,沒有效果;
分析:
查看原理並了解php運行過程,確實網站的fastcgi找不到php文件,但是我這邊配置好了php文件加載,配置如下:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 81;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.php index.html index.htm;
}
location ~*.*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
但是運行並測試時就提示找不到file not found,怎么辦?
解決方法:
為了正常顯示php時,就要讓他找到php網站目錄,只要在
location ~*.*\.(php|php5)?$ {
root html/blog; #網站目錄,增加這一行;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
重啟nginx,php服務后就可以顯示網站,如下 :
命令行:curl blog.etiantian.org:81/1.php
瀏覽器:
恢復正常了。