微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

最完美ThinkPHP Nginx 配置文件

一个配置文件,完美支持普通,兼容,pathinfo,rewrite4种url模式,别怪我没提醒你收藏哦. 常见的静态文件404时也不会再去跑一遍fastcgi浪费资源。

 

 

server {
    listen       80;
    server_name  localhost;
    root /var/www;
    index  index.html index.htm index.PHP;
    
    error_page  404              /404.html;
    location = /404.html {
        return 404 'Sorry, File not Found!';
    }
    
    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/Nginx/html; # windows用户替换这个目录
    }
    
    location / {
        try_files $uri @rewrite;
    }
    
    location @rewrite {
        set $static 0;
        if  ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
            set $static 1;
        }
        if ($static = 0) {
            rewrite ^/(.*)$ /index.PHP?s=/$1;
        }
    }
    
    location ~ /Uploads/.*\.PHP$ {
        deny all;
    }
    
    location ~ \.PHP/ {
       if ($request_uri ~ ^(.+\.PHP)(/.+?)($|\?)) { }
       fastcgi_pass 127.0.0.1:9000;
       include fastcgi_params;
       fastcgi_param SCRIPT_NAME     $1;
       fastcgi_param PATH_INFO       $2;
       fastcgi_param SCRIPT_FILENAME $document_root$1;
    }
    
    location ~ \.PHP$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
    location ~ /\.ht {
        deny  all;
    }
}

 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐