IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    修改Nginx支持ThinkPHP

    TacuLee发表于 2016-07-29 03:45:27
    love 0

    环境:

    1. CentOS 6.7
    2. LNMY 1.2

    nginx 配置目录:/usr/local/nginx/conf/vhost

    配置文件内容:

    server
        {
            listen 80;
            #listen [::]:80;
            server_name xxx.xxx.com;
            index index.html index.htm index.php default.html default.htm default.php;
            root  /xxx/xxx/xxx/xxx;
    
            location / {
            if (!-e $request_filename)
                {
                rewrite ^/(.*)$ /index.php/$1;
                #rewrite ^/ly/(.*)$ /ly/index.php/$1;
                }
            }
            
            #location ~ .*.(php|php5)?$
            location ~ .php
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
                set $path_info "";
                set $real_script_name $fastcgi_script_name;
    
                if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
                    set $real_script_name $1;
                    set $path_info $2;
                }
    
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;
     }
    
            location /status {
                stub_status on;
                access_log   off;
            }
    
            location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
    
            location ~ .*.(js|css)?$
            {
                expires      12h;
            }
            
            access_log  /home/wwwlogs/access.log  access;
        }

    注意事项:

    1. if放置的位置要在location /  里面;
    2. 检查配置文件:/usr/nginx/sbin/nginx -t;
    3. 重启nginx:/usr/nginx/sbin/nginx -s reload;
    4. 使用LNMY,直接lnmp restart.

    未经允许不得转载:TacuLee » 修改Nginx支持ThinkPHP



沪ICP备19023445号-2号
友情链接