2017-08-01 72 views
0

我在centos7上構建lnmp。然後我通過chrome訪問它。後果是:如何配置nginx

未找到文件。

我的nginx的配置文件是這樣的:

server { 
listen  80; 
server_name localhost; 

#charset koi8-r; 
#access_log /var/log/nginx/host.access.log main; 

location/{ 
    root /usr/share/nginx/html; 
    index index.php index.html index.htm; 
} 

#error_page 404    /404.html; 

# 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; 
} 

# proxy the PHP scripts to Apache listening on 127.0.0.1:80 
# 
#location ~ \.php$ { 
# proxy_pass http://127.0.0.1; 
#} 
# 添加下面內容 
location ~ \.php$ { 
    fastcgi_pass  127.0.0.1:9000; 
    fastcgi_index  index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; 
    include fastcgi_params; 
    #include fastcgi.conf; 
    } 

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
# 
#location ~ \.php$ { 
# root   html; 
# fastcgi_pass 127.0.0.1:9000; 
# fastcgi_index index.php; 
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
# include  fastcgi_params; 
#} 

# deny access to .htaccess files, if Apache's document root 
# concurs with nginx's one 
# 
#location ~ /\.ht { 
# deny all; 
#} 
} 

我的目錄:

[[email protected] html]$ pwd 
/usr/share/nginx/html 
[[email protected] html]$ ll 
total 35272 
-rw-r--r--. 1 michael www  15086 Jun 26 2016 favicon.ico 
-rw-rw-r--. 1 michael michael  7 Jul 31 21:49 index.html 
-rw-rw-r--. 1 michael michael  20 Jul 24 04:14 index.php 
-rw-r--r--. 1 michael www   432 Aug 5 2016 index.php.bak 
-rw-r--r--. 1 michael www  36085974 Feb 20 03:50 iwwenbo.zip 
drwxr-xr-x. 3 michael www   52 Aug 17 2016 sites 
[[email protected] html]$ cat index.php 
<?php 
phpinfo(); 
?> 

誰能告訴我?有什麼不對?我已經嘗試了很多次。它似乎無法找到一些文件,但index.php已經存在,我不知道哪個文件沒有找到。

+0

經典錯誤。 https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ root inside location –

回答

0

最後,我解決了這個問題。我修改了配置文件。

location ~ \.php$ { 
root /usr/share/nginx/html; 
fastcgi_pass  127.0.0.1:9000; 
fastcgi_index  index.php; 
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; 
include fastcgi_params; 
#include fastcgi.conf; 

}

是的,我添加一行root /usr/share/nginx/html;