tp5的nginx配置

环境采用阿里云的LNMP(OneinStack版),nginx默认不支持tp5的pathinfo。需要如下配置:

server {
  listen 80;
  server_name xxx.xxxx.com;
  access_log /data/wwwlogs/xxx.xxxx.log combined;
  error_log /data/wwwlogs/xxx.xxxxx_error.log;
  
  set $root /data/wwwroot/xxx.xxxx.com/public;

  location ~ \.php {
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param    SCRIPT_FILENAME    $root$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
    {
        root $root;
    }
    location / {
        root    $root;
        index    index.html index.php;
        if ( -f $request_filename) {
            break;
        }
        if ( !-e $request_filename) {
            rewrite ^(.*)$ /index.php/$1 last;
            break;
        }
    }
    
    
}

如果配置后还不好用,可以尝试把php.ini里的cgi.path_info 的值改为0,就可以了(会产生漏洞风险,需要进一步配置)。

此文参考:http://www.thinkphp.cn/topic/40391.html内容与评论。


你可能感兴趣的:(tp5的nginx配置)