Home Backend Development PHP Tutorial Nginx record request distribution log settings

Nginx record request distribution log settings

Jul 29, 2016 am 08:58 AM
html http request time

Copy after login
After nginx receives the request, it needs to distribute the request to the backend WEB service cluster.

You need to record the distribution log here to analyze the number of requests processed by each backend WEB server.

<pre name="code" class="python">http {
log_format  main  
  ' $remote_user [$time_local]  $http_x_Forwarded_for $remote_addr  $request '
 '$http_x_forwarded_for '                     
 '$upstream_addr '                      
 'ups_resp_time: $upstream_response_time '                      
 'request_time: $request_time';

access_log  logs/access.log  main;

server{}
...
}
Copy after login
The information displayed in the log is:
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.15:8188 ups_resp_time: 0.010 request_time: 0.011
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.16:8188 ups_resp_time: 0.006 request_time: 0.006
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.15:8188 ups_resp_time: 0.013 request_time: 0.013
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.17:8188 ups_resp_time: 0.003 request_time: 0.003
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.18:8188 ups_resp_time: 0.004 request_time: 0.004
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.15:8188 ups_resp_time: 0.012 request_time: 0.013
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.18:8188 ups_resp_time: 0.005 request_time: 0.005
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.16:8188 ups_resp_time: 0.011 request_time: 0.011
 - [31/May/2013:00:01:03 -0700]  - xxx.ip.addr.xxx  GET /portal/index.html HTTP/1.1 - 192.168.100.15:8188 ups_resp_time: 0.447 request_time: 0.759
Copy after login

All configuration files nginx.conf.
# greatwqs@163.com Install on 2012-08-11 linux
# user  devwqs;

# 2 intel(R) xeon(R) CPU
worker_processes  4;

worker_cpu_affinity 00000001 00000010 00000100 00001000;

# error_log  logs/error.log;
# error_log  logs/error.log  notice;
error_log   logs/error.log  error;

pid        logs/nginx.pid;

# allow openning file nums
worker_rlimit_nofile 25600;

events {
    # linux 2.6 upper version.
    use epoll;
    worker_connections  51200;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    # log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                   '$status $body_bytes_sent "$http_referer" '
    #                   '"$http_user_agent" "$http_x_forwarded_for"'
    #                   '"$upstream_addr"' '"$upstream_response_time"';
    log_format  main  ' $remote_user [$time_local]  $http_x_Forwarded_for $remote_addr  $request '
                      '$http_x_forwarded_for '
                      '$upstream_addr '
                      'ups_resp_time: $upstream_response_time '
                      'request_time: $request_time';

    access_log  logs/access.log  main;

    sendfile                     on;
    # tcp_nopush                 on;
                                 
    keepalive_requests           200;
    keepalive_timeout            20;
    gzip  on;                    
    client_body_buffer_size      128k;
    client_body_timeout          60s;
    client_max_body_size         10m;
    # proxy_buffer_size          8k;
    # proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size   64k;

    # portal-cluster
    upstream portal-cluster {
        # http://192.168.100.15:8188/portal/
        server 192.168.100.15:8188 weight=5 max_fails=5 fail_timeout=30s;

        # http://192.168.100.16:8188/portal/
        server 192.168.100.16:8188 weight=5 max_fails=5 fail_timeout=30s;
        
        # http://192.168.100.17:8188/portal/
        server 192.168.100.17:8188 weight=5 max_fails=5 fail_timeout=30s;
        
        # http://192.168.100.18:8188/portal/
        server 192.168.100.18:8188 weight=5 max_fails=5 fail_timeout=30s;
    }

    # manage-cluster
    upstream manage-cluster {
        # http://192.168.100.25:8189/manage/
        server 192.168.100.25:8189 weight=4 max_fails=5 fail_timeout=30s;

        # http://192.168.100.26:8189/manage/
        server 192.168.100.26:8189 weight=6 max_fails=5 fail_timeout=30s;
    }

    # External Internet.
    server {
        listen       80;
        server_name  www.huaxixiang.com;
        access_log   logs/host.access.log  main;

        location /portal/ {
            # root   html;
            # index  index.html index.htm;
            # nginx http header send to tomcat app.
            # proxy_set_header Host  $host;
            # proxy_set_header X-Forwarded-For  $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Real-Ip $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;

            proxy_pass http://portal-cluster;
        }

        # nginx status
        location /nginx_status {
            # copied from http://blog.kovyrin.net/2006/04/29/monitoring-nginx-with-rrdtool/
            stub_status  on;
            access_log   off;
            allow        192.168.100.100;
            #deny all;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    # External Internet.
    server {
        listen       80;
        server_name  manage.huaxixiang.com;

        access_log  logs/host.access.log  main;

        location /manage/ {
            proxy_pass http://manage-cluster;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
Copy after login

nginx status view:

Nginx 记录请求分发日志设置

The above introduces the Nginx record request distribution log settings, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles