Nginx 配置
1. 隐藏版本号
1.0 nginx:
http { .... server_tokens off; } 1.1 php:
expose_php = Off
2. 错误页面友好显示
1). 在http模块中开启:fastcgi_intercept_errors on; (注意必须开启,否则不生效)
2). 在http或者server模块配置下面参数
error_page 500 501 502 503 504 /error/5-error.html;
error_page 400 403 404 405 408 410 411 412413 414 415 /error/4-error.html;
注意:这里是相对路径,‘/’表示网站根目录,如果需要自定义目录的话,需要在下面添加location指定该目录位置
3). 确保在网站根目录下存在error和相关网页
3. 限制程序运行和文本读取
Nginx限制访问指定目录: location ~ ^/images/.*\.(php|php5|.sh|.pl|.py)$ { deny all; } 注意需要放在php解析location的下面 Nginx禁止访问*.txt,*.doc location ~* \.(txt|doc)$ { if (-f $request_filename) { root /data/www/www; #rewrite …..可以重定向到某个URL break; } }4. 限制ip访问
location / { deny 192.168.1.1; allow 192.168.1.0/24; allow 10.1.1.0/16; deny all; } 或者 if( $remote_addr = 10.0.0.7 ) { return 403; }5. 限制客户端类型和防止爬虫
防止爬虫 if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot") { return 403; } 禁止某类浏览器访问 if ($http_user_agent ~* "Firefox|MSIE") { return 403; rewrite ^(.*) http://blog.etiantian.org/$1 permanent; }6. 奇怪的问题
不能用87端口,奇怪!!!!!!!!!!!
浙公网安备 33010602011771号