thinkphp5配置nginx訪問

博客原文地址https://xgs888.top/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;
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章