Nginx的配置安全加固

# 2011 (C) cnpanel

# Disable visitors without agent
if ($http_user_agent ~ ^$) { return  412; }

# Disable possible Apache access files
location ~ /.ht {deny  all;}

# Never can not visit or download files or DIRs starting with #
location ~ /# {deny all;}

# Disable risk request in some DIRs for secure
location ~* /(image|images|img|imgs|upload|uploads|upimg|upimgs|upfile|upfiles|down|download|downloads|attachment|attachments|js|css|style|styles|tpl|template|templates|theme|themes|view|views|lang|language|languages|setting|settings|app|apps|include|includes|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)$ {deny all;}

这段代码需要放在server段里面(较前位置,最好放在location / {…}前面),也可以存成一个文件在每个vhost里include一下。

作者:cnpanel
via:hostloc