Nginx what things need to know?

Nginx (pronounced with engine x) is a framework for asynchronous Web server can also be used 作反向代理, 负载平衡器 and  HTTP 缓存. The software was created by Igor Sysoev, and the first public release in 2004. Of the same name was founded in 2011 to provide support. Nginx is a free open-source software, released under the terms of BSD-like license. Most use a Web server Nginx, usually as a load balancer. [1]

Nginx features

  • Faster:

    • Single request will get a faster response
    • In a highly concurrent environment, Nginx has a faster response than other web servers
  • High Scalability:

    • nginx is based on a modular design, a plurality of coupling modules low, thus having a high extensibility. Many high-traffic sites tend to develop custom modules in line with their business characteristics.
  • High reliability:

    • nginx reliability from its core framework code of good design, simplicity of modular design; in addition, the official common module are very stable, relatively independent of each worker process, master process can quickly pull up when a worker process error the new worker child processes to provide services.
  • Low memory consumption:

    • In general, 10,000 inactive HTTP  Keep-Alive connections Nginx consumed only 2.5MB of memory, which is nginx support high concurrent connection basis.
    • Stand-alone support more than 100,000 concurrent connections:理论上,Nginx 支持的并发连接上限取决于内存,10万远未封顶。
  • Hot deployment:

    • Separation design master process and worker processes that can provide Nginx hot deployment capabilities, that is the premise of 7x24-hour service, Nginx upgrade executable file. Of course, it also supports non-stop service to update the configuration item, replace the log files and other functions.
  • Most liberal BSD license:

    • This is a powerful driving force Nginx rapid development. BSD license allows users to not only free to use Nginx, it also allows users to use or modify the source code Nginx directly in your project and then publish. [2]

Built-in variable arguments detailed

  • Parameter value request $ args #
  • $query_string # 同 args
  • NAME value of $ arg_NAME # GET request
  • $ Is_args # If there is a request parameter value "?", Otherwise empty string
  • The current request URI $ uri # (without request parameters, parameters are located args) -, the value may be different from browser request_uri transmission, which can be internal redirect, modify or use the index instruction, the host name does not contain a URI such as "/foo/bar.html".
  • $ Document_uri # 同 sites
  • $ Document_root # the current request the document root or alias
  • $ Host # priority: HTTP request line hostname> "HOST" request header field> - in line with the request of the host name of the server header field in the request, if the host header in the request is not available, the server was server to process the request. name
  • $ Hostname # hostname
  • $ Https # If you turn SSL security mode is "on", otherwise empty string.
  • $ Binary_remote_addr # binary form of the address of the client, a fixed length of 4 bytes
  • $ Body_bytes_sent # number of bytes transmitted to the client, not counting the first response; variable and Apache mod_log_config module "% B" parameter compatibility
  • $ Bytes_sent # number of bytes transmitted to the client
  • $ Connection # serial number of a TCP connection
  • $ Connection_requests # TCP connection to the current number of requests
  • $ Content_length # "Content-Length" header field Request
  • $ Content_type # "Content-Type" request header field
  • $ Cookie_name # cookie name
  • $ Limit_rate # speed limit set for response
  • $ Msec # current Unix timestamp
  • $ Nginx_version # nginx version
  • PID $ pid # work processes
  • $ Pipe # If the communication request from the conduit, the value of "p", otherwise. ""
  • $ Proxy_protocol_addr # get access to the proxy server address of the client, if it is a direct access, the value is an empty string
  • The true path to the document root or alias $ realpath_root # the current request, all symbolic links will be converted to the true path
  • $ Remote_addr # client address
  • $ Remote_port # client port
  • Username services - $ remote_user # for HTTP basic authentication
  • $ Request # behalf of the client request address
  • $ Request_body # client request body: This variable can l- - ocation in use, through the request body proxy_pass, passing fastcgi_pass, uwsgi_pass scgi_pass and a proxy server to the next
  • $ Request_body_file # client request body is stored in a temporary file. After the file handle, the file to be deleted. If you need to turn on this feature, you need to set client_body_in_fi- le_only. If the file transfer times to the back-end proxy server, you need to disable the request body, that is set proxy_pass_request_body off, fastcgi_pass_request_body - off, uwsgi_pass_request_body off, or scgi_pass_request_body off
  • $ Request_completion # If the request succeeds, a value of "OK", if the request is not completed or the request is not the last part of a range requests, null
  • $ Request_filename # current file path connection request, or a request by the root URI generation instruction alias
  • $ Request_length # requested length (including the requested address, http request headers and the request body)
  • $ Request_method # HTTP request method, usually "GET" or "POST" -
  • $ Request_time # client request use of the time, in seconds, milliseconds accuracy; - starts from the first byte read client performed so far until the log is written to the last character transmitted after the client. -
  • $ Request_uri # this variable is equal to contain some of the original client request URI parameters, it can not be modified, check uri URI change or rewrite, does not include the host name, for example: "? / Cnphp / - test.php arg = freemouse"
  • $ Scheme # requests using a Web protocol, "http" or "https"
  • $ Server_addr # server address, should be noted that: In order to avoid access linux kernel, ip address should be set in advance in the configuration file
  • $ Server_name # server name
  • $ Server_port # server port
  • $ Server_protocol # HTTP server version, generally "HTTP / 1.0" or "HTTP / 1.1"
  • $ Status # HTTP response code
  • $ Time_iso8601 # server time of the ISO 8610 format
  • $ Time_local # server time (LOG Format format)
  • $ Cookie_NAME # cookie client request header Header variable, the prefix "cookie_" plus the name of the cookie variable, the variable's value is the value of the cookie name
  • $ Http_NAME # matches any request header field; NAME latter part of the variable name can be replaced with any request header fields, such as the need to obtain the http request in the configuration file header: "Accept-L- anguage", http_accept_language to
  • $ Http_cookie # cookie information
  • $ Http_host # request address, the browser address you entered (IP or domain name)
  • $ Http_referer # url jump source, used to record the access link from that page over
  • $ Http_user_agent # user terminal browser and other information
  • $http_x_forwarded_for
  • $ Sent_http_NAME # http response header may be provided in any field; NAME latter part of the variable name can be replaced with any response header field, such as the need to set the response header Content-length, s- ent_http_content_length to
  • $ Sent_http_cache_control # send http cache control
  • $ Sent_http_connection # Send http connection
  • $ Sent_http_content_type # send http type
  • $ Sent_http_keep_alive # send http connection remains
  • $ Sent_http_last_modified # http sent last modified
  • $ Sent_http_location # send http location
  • $ Sent_http_transfer_encoding- # http transmitting the encoded transmission [3]

Nginx logging example

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent $request_time "$http_referer" '                      '$host DIRECT/$upstream_addr $upstream_http_content_type '                      '"$http_user_agent" "$http_x_forwarded_for" '                      '"$Cookie_MEIQIA_EXTRA_TRACK_ID" "$Cookie_cpsInfo" "$Cookie_sid_account" "$Cookie_sid_user" "$Cookie_ss_user" "$Cookie_xxd_uid" "$Cookie_xxd_user" "$uid_got" "$uid_set"';

log_format explain some parameters

  • $ Proxy_protocol_addr # remote address (if enabled agency agreement)
  • The source IP address of the client $ remote_addr #
  • $ Remote_user # user name for HTTP basic authentication services
  • $ Time_local # access time and time zone
  • $ Request # request URI and HTTP protocol
  • $ Http_host # request address, the browser address you entered (IP or domain name)
  • $ Request # request URI and HTTP protocol
  • $ Http_host # request address, the browser address you entered (IP or domain name)
  • $ Status # HTTP request status
  • $ Upstream_status # upstream state
  • $ Body_bytes_sent # sent to the client file content size
  • $ Http_referer # url jump Source
  • $ Http_user_agent # user terminal browser and other information
  • $ Ssl_protocol # SSL protocol version
  • $ Ssl_cipher # data exchange algorithm
  • $ Upstream_addr # backstage upstream of address, host address really provide services
  • The total time of the entire request $ request_time #
  • $ Upstream_response_time # request process, upstream the response time [4]

Reference links

  • https://zh.wikipedia.org/wiki/Nginx
  • https://www.jianshu.com/p/99d50fcc5cd6
  • https://mooon.top/2019/03/25/blog/nginx%E5%86%85%E7%BD%AE%E5%8F%98%E9%87%8F%E4%BB%A5%E5%8F%8A%E6%97%A5%E5%BF%97%E6%A0%BC%E5%BC%8F%E5%8F%98%E9%87%8F%E5%8F%82%E6%95%B0%E8%AF%A6%E8%A7%A3/
  • https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/log-format/

Guess you like

Origin www.cnblogs.com/cheyunhua/p/12008971.html