前提操作
- 在php同級目錄下創建 index.html 看是否能訪問
可以訪問html,但php仍然出現 file not found
解決方案
location ~ \.php$ {
root /var/www/index;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 172.17.0.3:9000;
}
- 加上 root 項目地址; 這一個配置在當中
出現該問題原因
- 問題就在 nginx 配置文件上
location ~ \.php$ {
root /var/www/index;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 172.17.0.3:9000;
}
- 確保 root 的存在。有些人不用在這裏再加root這個配置,是因爲它已經在配置文件的外層已經定義了該配置。如樓下所示
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /var/www/index;
location / {
index index.php index.html index.htm;
}
...
...
記住不能配在 內層,這樣就會導致 $document_root 這個變量在整個配置文件其他範圍失效
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/index;
index index.php index.html index.htm;
}
...
...