Quickly set up Nginx and configure its basic parameters
This article mainly introduces the configuration of quickly setting up Nginx and its basic parameters. It has certain reference value. Now I share it with you. Friends in need can refer to
The quick setting up and basics of Nginx Parameters
1. Introduction to Nginx
1. Brief description of Nginx
Nginx is an open source, high-performance, reliable HTTP middleware and proxy service.
2. Common HTTP services
httpd - Apache
IIS - Microsoft
GWE - Google
tomcat - Sun
2. Why choose Nginx
1. IO multi-channel Multiplexing epoll
What is IO multiplexing
The I/O operations of multiple descriptors can be completed concurrently and alternately in one thread. This It's called I/O multiplexing. The "multiplexing" here refers to reusing the same thread.
What is epoll
How to implement IO multiplexing: select, poll, epoll
select
Basic principle:
The file descriptors monitored by the select function are divided into three categories, namely writefds, readfds, and exceptfds. After calling, the select function will block until a descriptor is ready (data is readable, writable, or except), or it times out (timeout specifies the waiting time, and it can be set to null if it returns immediately), and the function returns. When the select function returns, you can find the ready descriptor by traversing fdset.
select Disadvantages:
1. There is a maximum limit on the number of file descriptors that can be monitored.
2. Linear scanning is inefficient.
epoll
Basic principle:
epoll supports horizontal triggering and edge triggering. The biggest feature is edge triggering, which only tells the process Which fd has just become ready and will only be notified once. Another feature is that epoll uses the "event" readiness notification method to register the fd through epoll_ctl. Once the fd is ready, the kernel will use a callback-like callback mechanism to activate the fd, and epoll_wait can receive the notification.
Advantages of epoll:
1. There is no limit on the maximum concurrent connections, and the upper limit of FDs that can be opened is much greater than 1024 (1G of memory can monitor about 100,000 ports) .
2. The efficiency is improved. It is not a polling method, and the efficiency will not decrease as the number of FDs increases.
3. Memory copy, use mmap() file mapping memory to accelerate message passing with the kernel space; that is, epoll uses mmap to reduce copy overhead.
2. Lightweight
Fewer functional modules
Code modularization
3. CPU Affinity (affinity) is good
CPU affinity (affinity) is a way to bind the CPU core to the Nginx worker process, fixing each worker process to execute on one CPU, and reducing the CPU cache miss, for better performance.
4. sendfile
3. Quick setup and basic parameters of Nginx (CentOS7)
1. yum installation [Reference]
Create/etc/yum.repos.d/nginx.repo
file and enter the following content
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1
OS
Optional values arecentos
andrhel
.OSRELEASE
is the system version, for example,6
and7
represent versions 6.x and 7.x respectively.
Runyum install -y nginx
Install nginx
Runnginx -v
Check nginx version
[root~]# nginx -v nginx version: nginx/1.14.0
2. Detailed explanation of compilation parameters
View the compilation parameters during nginx installation
nginx -V
[root~]# nginx -V nginx version: nginx/1.14.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/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'
Detailed explanation of installation and compilation parameters [Reference]
Compile options | Function |
---|---|
--prefix =/etc/nginx |
Configuration file directory |
--sbin-path=/usr/sbin/nginx | Executable file name and directory |
#--modules-path=/usr/lib64/nginx/modules
| nginx dynamics Module installation directory|
--conf-path=/etc/nginx/nginx.conf
| Main configuration file name and directory|
--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 of the main request log file of the HTTP server and the directory |
--pid-path=/var/run/nginx.pid
| nginx.pid directory, this is the storage Process ID file of the main process|
--lock-path=/var/run/nginx.lock
| directory where nginx.lock is located|
--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 retained by nginx when executing the corresponding module|
--user=nginx
--group=nginx
| Set the user and user group for Nginx process startup|
--with-http_random_index_module
| Randomly select from the directory A random homepage|
--with-http_stub_status_module
| Nginx client status|
--with-http_sub_module
| HTTP content replacement|
Set additional parameters that will be added to the CFLAGS variable |
|
Set additional parameters and link to the system library |
rpm -ql nginx
Copy after login
[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
Copy after login
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
Type | Function | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Configuration file |
Nginx log rotation, used for log cutting of logrotate service | |||||||||||||||||||
/etc/nginx/nginx.conf /etc/nginx/conf.d /etc/nginx /conf.d/default.conf Directory, configuration file |
nginx main configuration file | |||||||||||||||||||
/etc/nginx/uwsig_params /etc/nginx/scgi_params Configuration file |
cgi Configuration related, fastcgi configuration | |||||||||||||||||||
/etc/nginx/koi-win /etc/nginx/win-utf Configuration file
| Encoding conversion mapping conversion file||||||||||||||||||||
Configuration file | Set the corresponding relationship between the Content-Type and extension of the http protocol||||||||||||||||||||
/usr/lib/systemd/system/nginx.service /etc/sysconfig/ nginx /etc/sysconfig/nginx-debug Configuration file
| is used to configure the system daemon manager management method||||||||||||||||||||
/etc/nginx/mudules Directory
| Nginx module directory||||||||||||||||||||
/usr/sbin/nginx-debug Command
| Terminal command for startup management of Nginx service||||||||||||||||||||
/usr/share/doc/nginx-1.14.0/COPYRIGHT /usr/share/man/man8/nginx.8.gz File, directory
| Nginx manual and help files||||||||||||||||||||
Directory | Nginx cache Directory||||||||||||||||||||
Directory | Nginx log directory
Explanation | |
---|---|
nginx [-c
| Start nginx with the specified configuration file|
Stop nginx normally and Nginx completes the accepted connection request before exiting. |
|
Quickly stops nginx, regardless of whether there are any requests being processed. |
|
Reload configuration file |
|
Reopen the log file |
|
View version |
|
View the compilation parameters during installation |
|
Check whether the syntax of the configuration file is correct |
Nginx load scheduler dual Tomcat load and session sharing MySQL back-end databaseRelated recommendations:
Nginx starts a new worker process and uses the new configuration file
Nginx allocates new requests to new worker processes
Nginx waits for all requests from previous worker processes to return, then closes the relevant worker processes
Repeat the above process until all old worker processes are closed
- The above is the entire content of this article, I hope it will help everyone learn Helpful, please pay attention to the PHP Chinese website for more related content!
The above is the detailed content of Quickly set up Nginx and configure its basic parameters. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.

Handling high DPI display in C can be achieved through the following steps: 1) Understand DPI and scaling, use the operating system API to obtain DPI information and adjust the graphics output; 2) Handle cross-platform compatibility, use cross-platform graphics libraries such as SDL or Qt; 3) Perform performance optimization, improve performance through cache, hardware acceleration, and dynamic adjustment of the details level; 4) Solve common problems, such as blurred text and interface elements are too small, and solve by correctly applying DPI scaling.

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.
