周梦康 发表于 2014-03-17 3467 次浏览 标签 : Nginx

配置404

更改nginx.conf在http定义区域加入:

fastcgi_intercept_errors on;

server 区域加入: 

error_page 404 = /404.html

配置301重定向

注意语法错误[emerg] unknown directive “if($host!=”

错误写法:

if($host != 'zhoumengkang.com'){ 
	rewrite ^(.*)$ http://zhoumengkang.com$1 permanent; 
}

正确写法:

if ( $host != 'zhoumengkang.com' ){ 
	rewrite ^(.*)$ http://zhoumengkang.com$1 permanent; 
}

伪静态

location / {
rewrite ^/?([0-9]+).html$                                       /index.php?m=Blog&a=blog&id=$1 last;
rewrite ^/?([0-9]+)-([0-9]+).html$                              /index.php?m=Blog&a=blog&id=$1&p=$2 last;
rewrite ^/?about.html$                                          /index.php?m=Blog&a=about last;
rewrite ^/?tags.html$                                           /index.php?m=Blog&a=tags last;
rewrite ^/?notebook.html$                                       /index.php?m=Blog&a=blogList&nav=1 last;
rewrite ^/?notebook-([0-9]+).html$                              /index.php?m=Blog&a=blogList&nav=1&p=$1 last;
rewrite ^/?homesick.html$                                       /index.php?m=Blog&a=blogList&nav=2 last;
rewrite ^/?homesick-([0-9]+).html$                              /index.php?m=Blog&a=blogList&nav=2&p=$1 last;
rewrite ^/?playground.html$                                     /index.php?m=Blog&a=blogList&nav=3 last;
rewrite ^/?playground-([0-9]+).html$                            /index.php?m=Blog&a=blogList&nav=3&p=$1 last;
rewrite ^/?tag-([0-9]+).html$                                   /index.php?m=Blog&a=readByTags&tag=$1 last;
}

拒绝 Web 访问 .svn 目录

location ~ ^(.*)\/\.svn\/{
        deny all;
        }

评论列表

回复 亮亮 2016-02-22 11:47:07
可以把更多常用的配置也加入进来