thinkphp5配置nginx访问

18 篇文章 0 订阅
3 篇文章 0 订阅

原文地址 https://xiegaosheng.com/post/view?id=68

 

 

thinkphp采用pathinfo模式;不像laravel和yii配置上去直接就可以干;

测试了两个不同方式的nginx安装 yum 和lnmp一键安装包;

一键安装包里面有对pathinfo的支持 

image.png

下面是配置

一键安装包安装的lnmp centos7

server
    {
        listen 8080 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /var/www/html/ibjson;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
		location / {
            if (!-e $request_filename){
                rewrite ^/(.*)$ /index.php?s=/$1 last;
            }
		}

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

 

 nginx端口转发的配置如下

server{
    listen      8089;
    server_name _;
    root           /var/www/html/tp5/public;
    index index.php index.html index.htm;

         location ~ \.php/?.* {  
      
                root           /var/www/html/tp5/public;  
      
                fastcgi_pass   127.0.0.1:9000;  
      
                 fastcgi_index  index.php;  
      
                 fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
      
                include        fastcgi_params;  
      
                #定义变量 $path_info ,用于存放pathinfo信息  
      
                 set $path_info "";  
      
                 #定义变量 $real_script_name,用于存放真实地址  
      
                 set $real_script_name $fastcgi_script_name;  
      
                 #如果地址与引号内的正则表达式匹配  
      
                 if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {  
      
                         #将文件地址赋值给变量 $real_script_name  
      
                         set $real_script_name $1;  
      
                         #将文件地址后的参数赋值给变量 $path_info  
      
                         set $path_info $2;  
      
                 }  
      
                 #配置fastcgi的一些参数  
      
                 fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;  
      
                 fastcgi_param SCRIPT_NAME $real_script_name;  
      
                 fastcgi_param PATH_INFO $path_info;  
      
             }  
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谢高升

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值