1.nginx301重定向跳转
[root@nginx nginx]
10 server {
11 listen 80;
12 server_name liang.com;
13 rewrite ^/(.*) http://www.liang.com/$1 permanent;
14 }
[root@nginx nginx]
nginx: the configuration file /usr/local/nginx-1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.6.2/conf/nginx.conf test is successful
[root@nginx nginx]
2.nginx防止恶意解析
[root@nginx nginx]
10 server {
11 listen 80;
12 location / {
13 deny all;
14 }
15 }
[root@nginx nginx]
nginx: the configuration file /usr/local/nginx-1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.6.2/conf/nginx.conf test is successful
[root@nginx nginx]
3.nginx日志配置与切割
3.1日志格式配置
nginx官网:关于日志模块的帮助
[root@nginx nginx]
10 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
11 '$status $body_bytes_sent "$http_referer" '
12 '"$http_user_agent" "$http_x_forwarded_for"';
24 server {
25 listen 80;
26 server_name www.liang.com;
27 location / {
28 root html/www;
29 index index.html index.htm;
30 access_log logs/access_www_log main;
31 }
32 }
[root@nginx nginx]
nginx: the configuration file /usr/local/nginx-1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.6.2/conf/nginx.conf test is successful
[root@nginx nginx]
[root@nginx nginx]
-rw-r--r--. 1 root root 569 Aug 5 12:35 logs/access_www_log
3.2按天切割日志
[root@nginx ~]
#!/bin/bash
Dir=/application/nginx/logs
File=access_www_log
cd ${Dir}
[ -f $File ]&&{
mv $File $(date +%F -d -1day)_$File
/application/nginx/sbin/nginx -s reload
}
[root@nginx ~]
00 00 * * * /bin/bash /server/scritp/ngins_log.sh >/dev/null 2>&1