This article mainly introduces the rapid construction of Nginx and its basic parameters of the configuration, has a certain reference value, now share to everyone, the need for friends can refer to
Quick setup and basic parameters of Nginx
First, Nginx Introduction
1. Nginx Description
Nginx is an open source and high-performance, reliable HTTP middleware, proxy services.
2. Common HTTP Services
Httpd-apache
IIS-Microsoft
Gwe-google
Tomcat-sun
Second, why Choose Nginx
1. IO multiplexing Epoll
What is IO multiplexing
I/O operations for multiple descriptors can be done alternately sequentially within a thread, which is called I/O multiplexing, where "multiplexing" refers to reusing the same thread.
What is Epoll
How
to implement IO multiplexing: Select, poll, Epoll
Select
Basic principle:
The Select function monitors file descriptors in 3 categories, Writefds, Readfds, and Exceptfds, respectively. After the call, the Select function blocks until a descriptor is ready (with data readable, writable, or except), or time-out (timeout Specifies the wait time, and if return is set to null immediately), the function returns. When the Select function returns, you can find the ready descriptor by traversing Fdset.
Select Cons:
1. There is a maximum limit on the number of file descriptors that can be monitored.
2. Linear scanning efficiency is low.
Epoll
Basic principle:
The epoll supports both horizontal and edge triggering, and the biggest feature is the Edge trigger, which only tells the process which FD has just become ready and only notifies once. Another feature is that Epoll uses the "Event" readiness notification method to register FD through EPOLL_CTL, and once the FD is ready, the kernel uses a callback mechanism similar to callback to activate the fd,epoll_wait to be notified.
Advantages of Epoll:
1. There is no limit to the maximum concurrent connection, the upper limit of the FD that can be opened is much larger than the minimum (1G of memory can listen to about 100,000 ports).
2. Efficiency gains, not polling, do not decrease as the number of FD increases in efficiency.
3. Memory copy, using mmap () file to map memory to accelerate message delivery to kernel space, that is, Epoll uses mmap to reduce replication overhead.
2. Lightweight
Fewer function modules
Modularity of code
3. CPU affinity (affinity) Good
CPU affinity (affinity) is a way to bind the CPU core and Nginx work process, each worker process is fixed on a CPU to execute, reduce the CPU cache miss, get better performance.
4. Sendfile
Three, the rapid construction and basic parameters of Nginx (CentOS7)
1. Yum-style Installation "Reference"
Create /etc/yum.repos.d/nginx.repo the file and enter the following:
[Nginx]name=nginx repobaseurl=http://nginx.org/packages/mainline/os/osrelease/$basearch/gpgcheck=0enabled=1
OS The optional values are
centos the and
rhel .
OSRELEASEfor the system version, for example,
6 and for
7 the 6.x and 7.x versions respectively.
Running the yum install -y nginx installation Nginx
Run nginx -v View Nginx version
[root~]# Nginx-vnginx version:nginx/1.14.0
2. Detailed compilation parameters
To view the compilation parameters at Nginx installation
Nginx-v
[root~]# Nginx-vnginx version:nginx/1.14.0built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k- FIPS Jan 2017TLS SNI support enabledconfigure arguments:--prefix=/etc/nginx--sbin-path=/usr/sbin/nginx--modules-pa Th=/usr/lib64/nginx/modules--conf-path=/etc/nginx/nginx.conf--error-log-path=/var/log/nginx/error.log-- Http-log-path=/var/log/nginx/access.log--pid-path=/var/run/nginx.pid--lock-path=/var/run/nginx.lock-- Http-client-body-temp-path=/var/cache/nginx/client_temp--http-proxy-temp-path=/var/cache/nginx/proxy_temp-- Http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp-- Http-scgi-temp-path=/var/cache/nginx/scgi_temp--user=nginx--group=nginx--with-compat--with-file-aio-- With-threads--with-http_addition_module--with-http_auth_request_module--with-http_dav_module--with-http_flv_ Module--with-http_gunzip_module--with-http_gzip_static_module--with-http_mp4_module--with-http_random_index_moDule--with-http_realip_module--with-http_secure_link_module--with-http_slice_module--with-http_ssl_module-- With-http_stub_status_module--with-http_sub_module--with-http_v2_module--with-mail--with-mail_ssl_module-- With-stream--with-stream_realip_module--with-stream_ssl_module--with-stream_ssl_preread_module--with-cc-opt= '- O2-g-pipe-wall-wp,-d_fortify_source=2-fexceptions-fstack-protector-strong--param=ssp-buffer-size=4- Grecord-gcc-switches-m64-mtune=generic-fpic '--with-ld-opt= '-wl,-z,relro-wl,-z,now-pie '
Install the compilation parameters in detail "Reference"
| compilation Options |
function |
--prefix=/etc/nginx |
Configuration file Directory |
--sbin-path=/usr/sbin/nginx |
Executable file name and directory |
--modules-path=/usr/lib64/nginx/modules |
installation directory of Nginx dynamic module |
--conf-path=/etc/nginx/nginx.conf |
The Master profile name and the directory in which it resides |
--error-log-path=/var/log/nginx/error.log |
Global error log file name and directory |
--http-log-path=/var/log/nginx/access.log |
The name and directory of the primary request log file for the HTTP server |
--pid-path=/var/run/nginx.pid |
Nginx.pid directory where the process ID file for the main process is stored |
--lock-path=/var/run/nginx.lock |
directory where Nginx.lock |
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
|
Temporary files reserved by Nginx when the corresponding module is executed |
--user=nginx
--group=nginx |
Set user and user groups for Nginx process startup |
--with-http_random_index_module |
Randomly select a random home page in the catalog |
--with-http_stub_status_module |
Nginx Client Status |
--with-http_sub_module |
HTTP content Substitution |
--with-cc-opt=<parameters> |
Setting additional parameters will be added to the cflags variable |
--with-ld-opt=<parameters> |
Set additional parameters, link system libraries |
3. Detailed Installation Catalogue
View the installation location of all nginx files
RPM-QL Nginx
[root~]# rpm-ql nginx/etc/logrotate.d/nginx/etc/nginx/etc/nginx/nginx.conf/ Etc/nginx/conf.d/etc/nginx/conf.d/default.conf/etc/nginx/fastcgi_params/etc/nginx/scgi_params/etc/nginx/uwsgi_ params/etc/nginx/koi-utf/etc/nginx/koi-win/etc/nginx/win-utf/etc/nginx/mime.types/etc/sysconfig/nginx/etc/ sysconfig/nginx-debug/usr/lib/systemd/system/nginx-debug.service/usr/lib/systemd/system/nginx.service/usr/ lib64/nginx/usr/lib64/nginx/modules/etc/nginx/modules/usr/sbin/nginx/usr/sbin/nginx-debug/usr/share/doc/ Nginx-1.14.0/usr/share/doc/nginx-1.14.0/copyright/usr/share/man/man8/nginx.8.gz/usr/share/nginx/usr/share/ nginx/html/usr/share/nginx/html/50x.html/usr/share/nginx/html/index.html/var/cache/nginx/var/log/nginx/usr/ Libexec/initscripts/legacy-actions/nginx/usr/libexec/initscripts/legacy-actions/nginx/check-reload/usr/libexec /initscripts/legacy-actions/nginx/upgrade
| Default Path |
type |
function |
/etc/logrotate.d/nginx |
Configuration file |
Nginx log rotation for log cutting of logrotate services |
/etc/nginx
/etc/nginx/nginx.conf
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf |
Directory, configuration file |
Nginx Master configuration file |
/etc/nginx/fastcgi_params
/etc/nginx/uwsig_params
/etc/nginx/scgi_params |
Configuration file |
CGI configuration-related, fastcgi configuration |
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/win-utf |
Configuration file |
Encoding conversion Mapping Conversion file |
/etc/nginx/mime.types |
Configuration file |
Set the Content-type of the HTTP protocol to the extension name |
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug |
Configuration file |
Used to configure how the System Daemon Manager is managed |
/usr/lib64/nginx/modules
/etc/nginx/mudules |
Directory |
Nginx Module Catalog |
/usr/sbin/nginx
/usr/sbin/nginx-debug |
Command |
Terminal commands for the startup management of Nginx Services |
/usr/share/doc/nginx-1.14.0
/usr/share/doc/nginx-1.14.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz |
Files, directories |
Nginx manuals and Help files |
/var/cache/nginx |
Directory |
Nginx Cache Directory |
/var/log/nginx |
Directory |
Nginx Log Directory |
Four, Nginx common commands
| Command |
explain |
nginx [-c <配置文件>] |
Start Nginx with the specified configuration file |
nginx -s quit |
Normal stop Nginx,nginx complete the accepted connection request before exiting. |
nginx -s stop |
Quickly stop Nginx, regardless of whether there is a request being processed. |
nginx -s reload [-c <配置文件>] |
Overloaded configuration Files |
nginx -s reopen |
Reopen log file |
nginx -v |
View version |
nginx -V |
To view compilation parameters at installation time |
nginx -t [-c <配置文件>] |
Check that the configuration file syntax is correct |
nginx -s reloadcommand to load the modified configuration file, the following event occurs after the command is released
Nginx Master Process Check the correctness of the configuration file, if the error is returned error message, Nginx continue to work with the original configuration file (because the worker is not affected)
Nginx starts a new worker process with a new configuration file
Nginx assigns new request to new worker process
Nginx waits for all requests from the previous worker process to return, shutting down the associated worker process
Repeat the above process until all the old worker processes are shut down
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!