针对Yii框架的nginx配置

Posted on 2014-05-23 14:53  CF3B5  阅读(459)  评论(0编辑  收藏  举报

我曾经针对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;
    }
 
}

 

Copyright © 2024 CF3B5
Powered by .NET 8.0 on Kubernetes