lsdwyl 发表于 2018-12-14 10:07:38

LNMP搭建3:测试PHP解析

  记得测试之前要关闭防火墙并禁止开机启动!!!!
  # iptables -F
  # iptables-save
  # Generated by iptables-save v1.4.7 on Fri Jan 13 00:27:50 2017
  *filter
  :INPUT ACCEPT
  :FORWARD ACCEPT
  :OUTPUT ACCEPT
  COMMIT
  # Completed on Fri Jan 13 00:27:50 2017
  # chkconfig iptables off
  1.安装好LNMP之后,使用浏览器访问服务器IP可以看到Nginx的欢迎页,证明安装成功。
https://s5.运维网.com/wyfs02/M01/8D/F4/wKioL1iwRhmgNI4NAAECqZjiBSI086.png-wh_500x0-wm_3-wmp_4-s_781926286.png
  2.这个欢迎页原文件在/nginx/html/目录下,这个目录下的文件可以直接被访问。
  # cd html
  # ls
  50x.htmlindex.html
  # cat index.html |less
  
  
  
  Welcome to nginx!
  
      body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
      }
  
  
  
  Welcome to nginx!
  If you see this page, the nginx web server is successfully installed and
  working. Further configuration is required.
  For online documentation and support please refer to
  nginx.org.
  Commercial support is available at
  ……
  3.要想解析php文件,需要编辑Nginx配置文件
  # vim /usr/local/nginx/conf/nginx.conf
  4.去掉php配置前面的注释符#,并更改网站根目录
  ……
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # 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_indexindex.php;
              fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name;
              include      fastcgi_params;
        }
  ……
  4.重新加载nginx配置文件:
  # nginx -s reload
  5.在网站根目录/usr/local/nginx/html/下添加一个info.php文件:
  # vim info.php
  
  6.使用浏览器看到已经可以解析PHP
https://s2.运维网.com/wyfs02/M02/8D/F6/wKiom1iwRizgAc29AAEkae93rwQ603.png-wh_500x0-wm_3-wmp_4-s_1080242544.png
  7.使用curl测试,默认访问的是index.html
  # curl localhost
  8.使用curl测试info.php
  # curl localhost/info.php
  




页: [1]
查看完整版本: LNMP搭建3:测试PHP解析