适用于使用Nginx进行部署的Web网站。php
熟悉Nginx配置,可以Nginx进行部署,并能针对站点使用Nginx进行安全加固。html
一、 根据站点开放端口,进程ID,确认站点采用Nginx进行部署;
二、 找到Nginx安装目录,针对具体站点对配置文件进行修改;
三、 在执行过程当中如有任何疑问或建议,应及时反馈。
详细操做nginx
如下为详细操做:web
修改配置,按以下设置日志记录文件、记录内容、记录格式,添加标签为main的log_format格式安全
1.(http标签内,在全部的server标签内能够调用): 2.log_format main ' $ remote_addr - remote_user [remote user[time_local] " $ request" ' 3.'$ status $ body_bytes_sent "“$ http_referer"' 4."$ http_user_agent" "$http_x_forwarded_for"';
access_log logs/host.access.log main并发
autoindex off;svg
#示例:去掉单个目录的PHP执行权限
location ~ /attachments/…(php|php5)?$ {
deny all;
}
i#示例:去掉多个目录的PHP执行权限
location ~
/(attachments|upload)/…(php|php5)?$ {
deny all;
}测试
一、以上的配置文件代码须要放到 location ~ .php{…}上面,若是放到下面是无效的;
二、attachments须要写相对路径,不能写绝对路径。网站
http {
…
fastcgi_intercept_errors on;
error_page 401 /401.html;
error_page 402 /402.html;
error_page 403 /403.html;
error_page 404 /404.html;
error_page 405 /405.html;
error_page 500 /500.html;
…
}
修改内容:
ErrorDocument 400 /custom400.html
ErrorDocument 401 /custom401.html
ErrorDocument 403 /custom403.html
ErrorDocument 404 /custom404.html
ErrorDocument 405 /custom405.html
ErrorDocument 500 /custom500.html
其中401.html、402.html、403.html、404.html、405.html、500.html 为要指定的错误提示页面。3d
server_tokens off;
if (request_method! ~(GET∣HEAD∣POST)$ ) {
return 444;
}
备注:只容许经常使用的GET和POST方法,顶多再加一个HEAD方法
location / {
deny 192.168.1.1; #拒绝IP
allow 192.168.1.0/24; #容许IP
allow 10.1.1.0/16; #容许IP
deny all; #拒绝其余全部IP
}
limit_zone one $binary_remote_addr 10m;
server
{
listen 80;
server_name down.test.com;
index index.html index.htm index.php;
root /usr/local/www;
#Zone limit;
location / {
limit_conn one 1;
limit_rate 20k;
}
………
}
user nobody;
location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {
valid_referers none blocked server_names *.nsfocus.com http://localhost baidu.com;
if ($invalid_referer) {
rewrite ^/ [img]http://www.XXX.com/images/default/logo.gif[/img];
#return 403;
}
}
查看软件版本 nginx -v
测试配置文件 nginx –t
手动安装补丁或安装最新版本软件