Nginx's main configuration file, generally defines the basic settings and global configuration of Nginx. Here is a detailed explanation of this configuration file:
File structure
#user nobody; worker_processes 1; #error_log logs/; #error_log logs/ notice; #error_log logs/ info; #pid logs/; events { worker_connections 1024; } http { include ; 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"'; #access_log logs/ main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; include /opt/nginx/conf/vhost/*.conf; }
Configuration details
1. Global configuration
#user nobody; worker_processes 1;
-
#user nobody;
: Commented out line to specify the user of the Nginx worker process. By default, Nginx runs as the user that starts it. -
worker_processes 1;
: Specify the number of Nginx worker processes. Usually set to the number of CPU cores to make the most of the multi-core processor.
2. Error log
#error_log logs/; #error_log logs/ notice; #error_log logs/ info;
-
#error_log logs/;
: Commented out line, used to specify the file path to the error log. -
#error_log logs/ notice;
: Commented line, used to specify the level of the error lognotice
。 -
#error_log logs/ info;
: Commented line, used to specify the level of the error loginfo
。
3. Process ID file
#pid logs/;
-
#pid logs/;
: Commented line to specify the PID file path of the Nginx main process.
4. Event module
events { worker_connections 1024; }
-
events
Block: Configure Nginx's event processing model. -
worker_connections 1024;
: Maximum number of concurrent connections per worker process. The total number of concurrent connections isworker_connections * worker_processes
。
5. HTTP module
http { include ; 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"'; #access_log logs/ main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; include /opt/nginx/conf/vhost/*.conf; }
-
include ;
: Contains MIME type configuration file to identify different types of files. -
default_type application/octet-stream;
: Set the default MIME type. -
#log_format main ...
: Commented out line to define the log format. -
#access_log logs/ main;
: Commented out line, used to specify the file path and format of accessing the log. -
sendfile on;
: Enable efficient file transfer mode to improve file transfer efficiency. -
#tcp_nopush on;
: Commented out line, used to control TCP's Nagle algorithm to reduce the transmission of small packets. -
#keepalive_timeout 0;
: Commented out line to close persistent connections. -
keepalive_timeout 65;
: Set the timeout time for persistent connections. -
#gzip on;
: Commented out line to enable Gzip compression. -
include /opt/nginx/conf/vhost/*.conf;
: Contains the virtual host configuration file, the path is/opt/nginx/conf/vhost/
All under.conf
document.
Summarize
This configuration file defines the basic settings of Nginx, including the number of worker processes, error logs, event processing model, basic configuration of HTTP modules, and the inclusion path of the virtual host configuration file. Through these configurations, Nginx can effectively handle various HTTP requests and support multiple virtual hosts.
This is the end of this article about in-depth understanding of nginx main configuration file. For more related nginx main configuration file content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!