The main configuration file nginx.conf of the Nginx service

Table of contents

Preface

1. Nginx.con location

2. Nginx.com related content

 3. Configuration blocks and instructions in Nginx.conf

1. I/O time configuration

2. HTTP configuration

Log format settings

Summarize


Preface

The main configuration file of Nginx is , which is usually located in the folder nginx.confunder the Nginx installation directory . confThe main configuration file nginx.confis the core configuration file of the Nginx service. It is used to define the global configuration of the server, the configuration of HTTP, HTTPS, proxy, load balancing, cache and other functions. 

1. Nginx.con location

/usr/local/nginx/conf/nginx.conf
 

2. Nginx.com related content

 3. Configuration blocks and instructions in Nginx.conf

1. I/O time configuration

This section defines how Nginx handles events. Common directives include worker_connections (set the maximum number of connections each worker process can handle simultaneously) and use (select the network I/O model).

If you want to increase the number of connections for each process, you need to execute the "ulimit -n 65535" command to temporarily modify the maximum number of files that each local process can open at the same time.

On the Linux platform, when processing high-concurrency TCP connections, the maximum number of concurrencies is limited by the system's limit on the number of files that a user can open at the same time in a single process (this is because the system creates a socket handle for each TCP connection. Each socket handle is also a file handle).

You can use the ulimit -a command to view the limit on the number of files the system allows the current user process to open.

2. HTTP configuration

This is the HTTP server configuration part of Nginx that handles HTTP requests and responses. Common directives include server (define a virtual host), location (match rules for request URLs) and include (introduce other configuration files).

  1. http: This is the HTTP server configuration part of Nginx, used to handle HTTP requests and responses. Common directives include server (define a virtual host), location (match rules for request URLs) and include (introduce other configuration files).

    • Server part: used to define a virtual host, where you can set the listening port, domain name, certificate, etc. Each server block corresponds to a virtual host.

      • location part: used to perform specific operations based on the requested URL matching rules. You can set up proxy, reverse proxy, cache, etc. Specific configuration items are selected as needed.
  2. Stream section: This is the TCP/UDP proxy server configuration section of Nginx, used to handle network traffic forwarding. Common directives include server (define a TCP/UDP virtual host) and upstream (define a backend server pool).

  3. Mail section: This is the Nginx mail proxy server configuration section, used to handle mail sending and receiving. Common directives include server (define a mail virtual host) and proxy (proxy to the backend mail server).

In addition, other configuration files can be introduced in the nginx.conf file, such as:

  • include mime.types: Contains configuration options for MIME types.
  • include conf.d/*.conf: Introduce all .conf files in the conf.d directory.
  • include sites-enabled/*: Introduces all configuration files in the sites-enabled directory.

Log format settings

$remote_addr and $http_x_forwarded_for are used to record the client’s IP address;

$remote_user: used to record the client user name;

$time_local: used to record access time and time zone;

$request: used to record the URL and http protocol of the request;

$status: used to record request status; success is 200,

$body_bytes_sent: records the size of the body content of the file sent to the client;

$http_referer: used to record the page link accessed from;

$http_user_agent: records relevant information of the customer's browser;

Summarize

Generally speaking, nginx.conf is the main configuration file of the Nginx server, which determines how Nginx handles different types of network requests. You can implement various functions such as HTTP server, proxy server, load balancing, etc. by properly configuring this file according to specific needs.

Guess you like

Origin blog.csdn.net/m0_71888825/article/details/131363649