美文网首页
nginx配置tp3.2

nginx配置tp3.2

作者: 奋斗live | 来源:发表于2019-03-30 23:19 被阅读0次
    一、环境准备

    这里我采用的是 centos7.2

    二、开启php-fpm

    这里对于php和nginx的安装就不介绍了,可以看我其他几篇博文,里面有介绍了yum 安装php 和源码编译安装nginx

    service php-fpm restart
    service php-fpm status
    

    如下显示,则代表已开启成功

    image.png
    三、配置nginx

    让nginx配置引入外部配置文件,vim nginx.conf,加入如下代码

     include /usr/local/nginx/conf/vhost/*.conf;
    

    如下图所示


    image.png

    在 /usr/local/nginx/conf/vhost下随便编辑以.conf 为后缀的配置文件
    若没有 vhost目录,则手动创建一个
    创建外部配置文件如下

    server {
            listen       80;
            server_name  testshop.test.cn;
            #charset koi8-r;
            #access_log  logs/host.access.log  main;
            location / {
                root   testshop.test.cn;;
                index  index.html index.htm index.php;
                if (!-e $request_filename) {  #这个if语句里面是要必加的
                   rewrite ^/(.*)$ /index.php?s=$1 last;
                   break;
                 }
            }
            location ~ \.php {
                set $script $uri;
                set $path_info "/";
                if ($uri ~ "^(.+\.php)(/.+)") {
                    set $script $1;
                    set $path_info? $2;
                }
                root           /www/testshop.test.cn;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               include        fastcgi_params;
            }
         }
    
    
    四、重启nginx测试

    进入sbin目录中

    ./nginx -s reload
    

    访问站点进行测试
    如下已经配置成功了


    image.png

    相关文章

      网友评论

          本文标题:nginx配置tp3.2

          本文链接:https://www.haomeiwen.com/subject/yruebqtx.html