dd

Yii框架在nginx下的配置

jerry Yii 2015年08月09日 收藏
  • rewrite规则(try_file),需要nginx0.8.6版本以上支持。

  • 针对于icon, robots.txt文件的日志优化

  • .svn, .git,等版本控制文件的忽略,以及Mac本身索引文件目录

  • Yii框架本身应该禁止web访问的目录。

  • 图片等静态文件缓存优化

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;
    }
 
}


dd