原文鏈接:https://www.akii.org/nginx-config-for-yii.html
我曾經針對yii制作了 個nginx配置,其中包括了以下幾項內容:
- rewrite規則(try_file),需要nginx0.8.6版本以上支持。
- 針對於icon, robots.txt文件的日志優化
- .svn, .git,等版本控制文件的忽略,以及Mac本身索引文件目錄
- Yii框架本身應該禁止web訪問的目錄。
- 圖片等靜態文件緩存優化
在這里分享一下demo
server { listen 80; server_name youdomain.com; index index.html index.htm index.php; root /home/wwwroot/htdocs/yii-1.1.8.r3324/demos/blog; #charset koi8-r; # 這里的main,是nginx默認的httpd段的一個日志格式定義 access_log /home/wwwlogs/localhost.access.log main; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # #error_page 500 502 503 504 /50x.html; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } ################ Yii framework rule ################# location / { try_files $uri $uri/ /index.php?$args; } location ~ /(protected|framework|nbproject|themes/\w+/views|index-test\.php) { deny all; # for production internal; log_not_found off; access_log off; } ################ for Yii framework end ################# location ~ \.php$ { fastcgi_pass php; fastcgi_index index.php; include fastcgi.conf; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /(\.svn|\.git|\.ht|\.DS) { deny all; internal; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } }
location / {
try_files $uri $uri/ /index.php?$args;
}
不加$args也可以吧?
作者答:不加的話,比如你url中含有?a=b這種get參數,可能就傳遞不過去了。
