search
HomeBackend DevelopmentPHP TutorialQuickly 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 ​​are centos and rhel.
OSRELEASE is the system version, for example, 6 and 7 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]

nginx dynamics Module installation directoryMain configuration file name and directoryGlobal error log file name and directoryThe name of the main request log file of the HTTP server and the directory nginx.pid directory, this is the storage Process ID file of the main processdirectory where nginx.lock is locatedTemporary files retained by nginx when executing the corresponding moduleSet the user and user group for Nginx process startup Randomly select from the directory A random homepageNginx client statusHTTP content replacement#--with-cc-opt=--with-ld-opt=3. Detailed explanation of the installation directory
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
--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-http_random_index_module
--with-http_stub_status_module
--with-http_sub_module
Set additional parameters that will be added to the CFLAGS variable
Set additional parameters and link to the system library

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/ etc/logrotate.d/nginx /etc/nginx/etc/nginx /fastcgi_params##/etc/nginx/koi-utfEncoding conversion mapping conversion file/ etc/nginx/mime.typesSet the corresponding relationship between the Content-Type and extension of the http protocol/usr/lib/systemd/system/nginx-debug.service is used to configure the system daemon manager management method/usr/lib64/nginx/modules Nginx module directory/usr/sbin/nginxTerminal command for startup management of Nginx service/usr/share/doc/nginx-1.14.0Nginx manual and help files/var/cache/nginxNginx cache Directory/var/log/nginxNginx log directory

4. Nginx common commands

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
Configuration file
/usr/lib/systemd/system/nginx.service
/etc/sysconfig/ nginx
/etc/sysconfig/nginx-debug
Configuration file
/etc/nginx/mudules
Directory
/usr/sbin/nginx-debug
Command
/usr/share/doc/nginx-1.14.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
File, directory
Directory
Directory
##CommandExplanationStart nginx with the specified configuration file##nginx -s quitnginx -s stopnginx -s reload [-c ]nginx -s reopennginx -vnginx -V# #nginx -t [-c ]## The nginx -s reload
nginx [-c ]
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
command loads the modified configuration file. After the command is issued, the following events occur

The master process of Nginx checks the correctness of the configuration file. If it is an error, an error message will be returned, and nginx will continue to use the original configuration file to work (because the worker is not affected)
  1. Nginx starts a new worker process and uses the new configuration file

  2. Nginx allocates new requests to new worker processes

  3. Nginx waits for all requests from previous worker processes to return, then closes the relevant worker processes

  4. Repeat the above process until all old worker processes are closed

  5. 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!
Related recommendations:

Nginx load scheduler dual Tomcat load and session sharing MySQL back-end database

Use nginx in Deploy multiple Web Servers on one server

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft