ThinkPHP

ThinkPHP5 Nginx 配置

2017-07-03  本文已影响336人  芳君君

小弟配置 Nginx 力求简单明了,禁止直接调用 .php 文件,杜绝安全隐患,同时允许读取静态资源文件。

server
{
    listen    80;
    server_name   thinkphp.com;
    index index.html index.htm index.php;
    root /usr/local/web/thinkphp/public;
    # 禁止读取 svn 文件
    location ~ ^(.*)\/\.svn\/ 
    {
            return 404;
    }
    # 禁止允许 .php 文件
    location ~ \.php 
    {
            return 444;
    } 
    # 允许访问静态资源
    location ~ (/static/)|(favicon\.ico$) 
    {
            try_files $uri =404;
    }
    location / 
    {
        # try_files $uri  /index.php?$query_string;
        rewrite ^/(.*)$ /index.php?s=/$1;
        location = /index.php  
        {
             # 开启 PATH_INFO 
            fastcgi_split_path_info ^(.+\.php)(.*)$; 
            fastcgi_param PATH_INFO $fastcgi_path_info; 
            fastcgi_pass   unix:/dev/shm/php-cgi.sock;
            fastcgi_index  index.php;
            include fastcgi.conf;
        }
    }
}

引用:
简单配置nginx使之支持pathinfo

老朱亲自写的,最完美ThinkPHP Nginx 配置文件

thinkphp5 的 nginx 配置文件

上一篇 下一篇

猜你喜欢

热点阅读