1 Core configuration
-
Setting the user of the worker process refers to the user in linux, which involves some permissions for nginx to manipulate directories or files. The default is
nobody
user root;
-
Set the number of worker processes. Generally speaking, if there are a few CPUs, just set a few, or set it to N-1.
worker_processes 1;
-
nginx log level debug | info | notice | warn | error | crit | alert | emerg , the error level increases from left to right
-
Set nginx process pid
pid logs/nginx.pid;
-
Set working mode
events { # 默认使用epoll use epoll; # 每个worker允许连接的客户端最大连接数 worker_connections 10240; }
-
http is a command block, some command configuration for http network transmission
http { }
-
include introduces external configuration to improve readability and avoid too large a single configuration file
include mime.types;
-
Set the log format,
main
a format defined name, soaccess_log
you can directly use the variablesparameter name Parameter meaning $remote_addr Client ip $remote_user Remote client user name, generally:'-' $time_local Time and time zone $request Requested url and method $status Response status code $body_bytes_send Response client content bytes $http_referer Record which link the user jumped from $http_user_agent The proxy used by the user usually comes from a browser $http_x_forwarded_for Record the client's ip through the proxy server -
sendfile
Use efficient file transfer to improve transfer performance. It can be used only after ittcp_nopush
is enabled , which means that the data table is sent only after it has accumulated a certain size, which improves the efficiency.sendfile on; tcp_nopush on;
-
keepalive_timeout sets the timeout time between client and server requests to ensure that new connections will not be repeatedly established when the client requests multiple times, saving resource consumption.
#keepalive_timeout 0; keepalive_timeout 65;
2 Common commands
2.1 Stop
1 Stop violence ( 不推荐
)
[root@localhost ~]# /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx -s stop
2 Wait for the request to end, and then close (only for http 推荐
)
[root@localhost sbin]# ./nginx -s quit
2.2 Verify configuration file
[root@localhost sbin]# ./nginx -t
2.3 View version number and specific information
[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.16.1
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi
2.4 Prompt command
[root@localhost sbin]# ./nginx -h
nginx version: nginx/1.16.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: /usr/local/nginx/conf/nginx.conf)
-g directives : set global directives out of configuration file
2.5 Reload the configuration file
[root@localhost sbin]# ./nginx -s reload
2.5 Specify the core configuration file
[root@localhost sbin]# ./nginx -c test.conf
3 Related information
- **The blog post is not easy, everyone who has worked so hard to pay attention and praise, thank you**