centos7搭建Lnmp环境

各位大神,我搭建完lnmp环境之后,通过ip访问,出现以前问题

图片描述

下面是我的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;
    #}
}

我的目录:

[michael@localhost html]$ pwd
/usr/share/nginx/html
[michael@localhost 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
[michael@localhost html]$ cat index.php
<?php
phpinfo();
?>

请帮我看看问题出在哪里?

阅读 3.3k
4 个回答

方式一

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

方式二


server {
    root   /usr/share/nginx/html;#sever中增加这段
}

root /usr/share/nginx/html; 写到server下.不然对php的location来说不生效吧

你这个 File not found 不是 nginx 报出来的吧。
就是你 index.php 中的内容?(里面的内容是什么)

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

没有斜杠

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题