nginx 配置 ThinkPHP Rewrite

server {
     listen       80;
     server_name  www.funsion.com;
     root /www/web/funsion;
     index  index.php;
     location / {
        # 不帶www的時候,自動加上www
        if ($host !~ '^www') {
            rewrite "^/(.*)$" http://www.$host/$1 permanent;
         }

        if (!-e $request_filename){
             rewrite ^/(.*)$ /index.php/$1 last;
        }
     }     

     location ~ .*\.(php|php5)?$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
        
        # 自定義服務器環境變量
        fastcgi_param DB_TYPE 'mysql';
        fastcgi_param DB_HOST '127.0.0.1';
        fastcgi_param DB_NAME 'funsion_db';
        fastcgi_param DB_USER 'wfc';
        fastcgi_param DB_PWD '123456';
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
        expires 30d;
    }

    location ~ .*\.(js|css)?$ {
        expires 1d;
    }

    location ~ ^(/ThinkPHP|/Application|/Runtime|/Db|/Addons|/.git)/ {      
        # 防止核心文件被訪問
         return 404;
    }

    access_log  /home/log/nginx/access/www.test.com.log;
    error_log  /home/log/nginx/www.test.com.error.log;

}            
相關文章
相關標籤/搜索