Nginx Config
This post analyzes the Config of Nginx.
1. Nginx Config
| |
| |
| |
| |
The nginx.conf file contains the main configuration of Nginx. [File 1] shows an example of nginx.conf, and it Includes [File 2 ~ 4]. This post analyzes the configuration contents of [File 1 ~ 4].
1.1. nginx.conf Top
| |
user: Specifies the User of the Nginx Worker Processes. It is used to set the permissions of the Worker Processes.worker-processes: Specifies the number of Nginx Worker Processes. The default value is 1.error-log: Specifies the path of the Nginx Error Log.pid: Specifies the path of the Log where the PID of the Nginx Master Process is stored.worker-rlimit-nofile: Specifies the maximum number of File Descriptors that a Nginx Worker Process can use. It is generally set to twice the maximum number of Connections that a Worker Process can have. The default value is 1024.
1.2. events Block
| |
The events Block contains configuration related to Network Connection handling.
worker-connections: Specifies the maximum number of Connections that a Nginx Worker Process can have simultaneously.
1.3. http Block
The http Block contains HTTP and HTTPS related configuration.
1.3.1 http Block Top
| |
include mime.types: Includes [File 2]. It configures the MIME (Multipurpose Internet Mail Extensions) types used by Nginx. MIME refers to an Encoding/Decoding technique for transmitting files such as Images and Videos in Text form.include proxy.conf: Includes [File 3]. It applies the Reverse Proxy related configuration of Nginx.include fastcgi.conf: Includes [File 4]. It applies the FastCGI related configuration.index: Specifies the Index Page.
| |
default-type: Specifies the Default MIME type.log-format: Specifies the format of the HTTP and HTTPS processing Log. The default value istext/plain.access-log: Specifies the path of the HTTP and HTTPS processing Log.sendfile: Specifies whether to use thesendfile()System Call when transmitting Static Files (Image, Video). Thesendfile()System Call is faster than the conventionalread()/write()System Calls because Data transfer between two File Descriptors is performed based on Zero Copy entirely at the Kernel Level.tcp-nopush: Specifies whether to setTCP-CORKon the TCP Socket when using thesendfile()System Call.TCP-CORKmakes Packets sent to the TCP Socket accumulate in the TCP Socket Buffer and be sent at once. It is meaningful only whensendfile onis set.server-names-hash-bucket-size: Specifies the maximum number of Server Names that can be registered in Nginx.
| |
proxy-redirect: Specifies whether to change the HTTPLocationandRefreshHeaders of the Response received from Nginx’s Proxied Server. The HTTPLocationHeader is a Header that holds the URL of the changed Resource when the location of a Resource has changed. The HTTPRefreshHeader is a Header that instructs the Client to Refresh.proxy-set-header Host: Sets the HTTPHostHeader. The HTTPHostHeader is a Header that stores which Virtual Host (Server) processed the request.proxy-set-header X-Real-IP: Sets the HTTPX-Real-IPHeader. The HTTPX-Real-IPHeader is a Header that stores the Client’s IP information.proxy-set-header X-Forwarded-For: Sets the HTTPX-Forwarded-ForHeader. The HTTPX-Forwarded-ForHeader is a Header that stores the Client’s IP information.client-max-body-size: Specifies the maximum allowed Body Size of a Client Request.client-body-buffer-size: Specifies the size of the Read Buffer for the Body of a Client Request.
| |
proxy-connect-timeout: Specifies the maximum wait time required to establish a TCP Connection.proxy-send-timeout: Specifies the maximum wait time required to send the Client’s Request to the Proxied Server.proxy-read-timeout: Specifies the maximum wait time required to receive a Response from the Proxied Server.proxy-buffers: Specifies the size of the Read Buffer used per Connection with the Proxied Server. The values specify, in order, the number of Buffers and the size of each Buffer.
1.3.2. http Block server Block
One server Block represents one Virtual Server. A Virtual Server has the same meaning as a Virtual Host of the Apache HTTP Server.
| |
It is configured to operate as a Reverse Proxy for a PHP Application using FastCGI.
listen: Specifies the Listen Port of the Virtual Server.server-name: Specifies the name of the Virtual Server. It is usually set to a Domain name.access-log: Specifies the path of the Log related to the Virtual Server.locationBlock : Configured to use the PHP Application that uses FastCGI.
| |
It is configured to operate as a Reverse Proxy.
- First
locationBlock : Configured to serve the Static Files under therootpath. - Second
locationBlock : Configured to operate as a Reverse Proxy for the127.0.0.1:8080Port.
| |
It is configured to operate as a Reverse Proxy that performs Load Balancing.
upstreamBlock : Specifies the Target Servers to which the Packets distributed by Nginx’s Load Balancing are delivered.locationBlock : Configured to perform Load Balancing using the Load Balancing Target Servers set in theupstreamBlock.
2. References
- NGINX Full Example Configuration : https://www.nginx.com/resources/wiki/start/topics/examples/full/
- Nginx worker_rlimit_nofile : https://stackoverflow.com/questions/37591784/nginx-worker-rlimit-nofile