nginx安全配置


#only allow there request methods
if ($request_method !~ ^(GET|HEAD|POST)$) {
rewrite ^(.*) /404.html;
}
# Disable visitors without agent
if ($http_user_agent ~ ^$) { rewrite ^(.*) /404.html;}

if ($request_uri ~* "(2fwindows)|(windows)|(passwd)|(blockquote)|(denyMethodExecution)") {
rewrite ^(.*) /404.html; 
}
if ($request_uri ~* "(script\()|(alert\()|(expression\()|(print\()|(md5\()|(die\()|(fromCharCode\()|(getResponse\()|(getWriter\()|(ServletActionContext\()|(println\()|(exec\()|(getRuntime\()|(DataInputStream\()|(getInputStream\()|(String\()") {
rewrite ^(.*) /404.html; 
}

location ~^/(WEB-INF)/{
	rewrite ^(.*) /404.html;
}
	   
location ~ .*.(asp|php|mdb|zip|rar)$ {
   rewrite ^(.*) /404.html;
}
if ($request_uri ~* "(cost\()|(concat\()") {
rewrite ^(.*) /404.html; 
}
if ($request_uri ~* "[+|(%20)]union[+|(%20)]") {
rewrite ^(.*) /404.html;
}
if ($request_uri ~* "[+|(%20)]and[+|(%20)]") {
rewrite ^(.*) /404.html;
}
if ($request_uri ~* "[+|(%20)]select[+|(%20)]") {
rewrite ^(.*) /404.html;
}

# Disable possible Apache access files
location ~ /\.ht {rewrite ^(.*) /404.html;}
# Never can not visit or download files or DIRs starting with #
location ~ /\# 
{rewrite ^(.*) /404.html;}
# Disable risk request in some DIRs for secure
location ~* /(htmlpage|picture|company|image|images|img|imgs|upload|uploads|upimg|upimgs|upfile|upfiles|down|download|downloads|attachment|attachments|js|css|style|styles|tpl|theme|themes|view|views|lang|language|languages|setting|settings|app|apps|class|classes|mod|mods|model|models|lib|libs|control|controls|source|sources|plugin|plugins|data|datas|database|tmp|temp|ipdata|html|avatar|avatars)/(.*)\.(php|php3|php4|php5|cgi|asp|aspx|jsp|shtml|shtm|pl|cfm|sql|mdb|dll|exe|com|inc|sh)$ {
	rewrite ^(.*) /404.html;
}



nginx的安全配置,可以include来用
目前的策略原则是,普通目录都是555,部分能写的目录不让动态访问,

你可能感兴趣的:(nginx)