Nginx 负载&日志配置

新增了一台Server,如是增加几个节点,用起了,负载均衡,大家可以参考参考

 

upstream  www.duzhi.me {
   server 10.105.82.28:8080;
   server 10.154.137.106:18080;
  server 10.154.137.106:28080;         
} 

修改了Access log 配置:

log_format main '$remote_addr - $remote_user [$time_local] fwf[$http_x_forwarded_for] tip[$http_true_client_ip] $upstream_addr $upstream_response_time $request_time  $
http_host $request "$status" $body_bytes_sent "$http_referer" "$http_accept_language" "$http_user_agent" ';

 

123.125.71.97 - - [04/May/2017:10:09:52 +0800] fwf[-] tip[-] 10.154.137.106:18080 0.076 0.109  www.duzhi.me GET /history/4001.html HTTP/1.1 "200" 13329 "-" "zh-cn,zh-tw" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" 
183.61.13.173 - - [04/May/2017:10:11:15 +0800] fwf[125.88.223.58] tip[-] 10.105.82.28:8080 0.003 0.066  www.duzhi.me GET / HTTP/1.1 "200" 55019 "-" "-" "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322) 360JK yunjiankong 1226555" 
123.125.46.173 - - [04/May/2017:10:12:08 +0800] fwf[111.206.241.75] tip[-] 10.154.137.106:28080 0.086 0.114  www.duzhi.me GET / HTTP/1.1 "200" 55144 "-" "-" "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322) 360JK yunjiankong 1226555" 
180.153.100.141 - - [04/May/2017:10:12:11 +0800] fwf[-] tip[-] 10.154.137.106:18080 0.129 0.131  www.duzhi.me GET / HTTP/1.1 "200" 55144 "-" "-" "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322) 360JK yunjiankong 1226555" 
220.181.108.175 - - [04/May/2017:10:12:19 +0800] fwf[-] tip[-] 10.105.82.28:8080 0.003 0.037  www.duzhi.me GET /subs/min/min.ar HTTP/1.1 "404" 1016 "-" "zh-cn,zh-tw" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" 
122.246.3.22 - - [04/May/2017:10:12:35 +0800] fwf[180.153.81.158] tip[-] 10.154.137.106:28080 0.003 0.003  www.duzhi.me GET / HTTP/1.1 "200" 15073 "-" "*" "DNSPod-Monitor/2.0" 

从上面我们可以看出几部分信息:

1.客户端(用户)IP地址。如:上例中的 201.158.69.116

2.访问时间。如:上例中的 [03/Jan/2013:21:17:20 -0600]

3.访问端口。如:上例中的 127.0.0.1:9000

4.响应时间。如:上例中的 0.007

5.请求时间。如:上例中的 0.007

6.用户地理位置代码(国家代码)。如:上例中的 MX(墨西哥)

7.请求的url地址(目标url地址)的host。如:上例中的 pythontab.com

8.请求方式(GET或者POST等)。如:上例中的 GET

9.请求url地址(去除host部分)。如:上例中的 /html/test.html

10.请求状态(状态码,200表示成功,404表示页面不存在,301表示永久重定向等,具体状态码可以在网上找相关文章,不再赘述)。如:上例中的 "200"

11.请求页面大小,默认为B(byte)。如:上例中的 2426

12.来源页面,即从哪个页面转到本页,专业名称叫做“referer”。如:上例中的 "http://a.com"

13.用户浏览器语言。如:上例中的 "es-ES,es;q=0.8"

14.用户浏览器其他信息,浏览器版本、浏览器类型等。如:上例中的  "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"

 

详细配置如下,大家可以参考参考:PS:ip是的内网IP;

 

upstream  www.duzhi.me {
   server 10.105.82.28:8080;
   server 10.154.137.106:18080;
  server 10.154.137.106:28080;         
} 


log_format main '$remote_addr - $remote_user [$time_local] fwf[$http_x_forwarded_for] tip[$http_true_client_ip] $upstream_addr $upstream_response_time $request_time  $
http_host $request "$status" $body_bytes_sent "$http_referer" "$http_accept_language" "$http_user_agent" ';

server
    {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
        server_name  s.duzhi.me www.duzhi.me java.duzhi.me awen.cc ipu.red www.ipu.red;
        #error_page   404   /404.html;
        index index.html index.htm index.jsp;
        proxy_ignore_client_abort on;
        root /data_disk/data/html/jduzhi/ROOT;
                            
    if ( $host != 'www.duzhi.me' ){
                rewrite ^/(.*)$ http://www.duzhi.me/$1 permanent;
                                }
       location / {
                proxy_pass http://www.duzhi.me;
                proxy_set_header X-Forward-For $HTTP_REMOTE_USER_IP ;
                proxy_set_header X-real-ip $remote_addr;
       }


        location ^~  /admin/druid/ {
                proxy_pass http://java.duzhi.me:8080;
                proxy_set_header X-Forward-For $HTTP_REMOTE_USER_IP ;
                proxy_set_header X-real-ip $remote_addr;
       }

        location ~.*\.(js|css|gif|jpg|jpeg|png|bmp|swf|woff)$ {
                                        expires       15d;
                                        root /data_disk/data/html/jduzhi/ROOT;
        }



access_log  /home/wwwlogs/www.duzhi.me.access.log main;

        #access_log  /home/wwwlogs/www.duzhi.me.access.log;
    }

除特别注明外,本站所有文章均为duzhi原创,转载请注明出处来自https://www.duzhi.me/article/4204.html

联系我们

******

在线咨询:点击这里给我发消息

邮件:ashang.peng#aliyun.com

QR code