Home  >  Article  >  Operation and Maintenance  >  How to compile and install Nginx

How to compile and install Nginx

王林
王林forward
2023-05-19 23:58:055233browse

1. Download the nginx source file

Enter the nginx official website to download the stable version of nginx. I downloaded 1.10.0.

Unzip: tar -zxvf nginx-1.10.0.tar.gz

## 2. Check the installation dependencies

Execute the following command to install nginx dependent libraries:

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

3. Configure nginx installation options

I only configure the installation to the /opt directory here , other options can be viewed by executing ./configuration –help.


cd nginx installation directory, execute the following command:

./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx

Official website parameter configuration instructions:

4. Compile and install

make && make install

5. Start, stop, restart

# 1.启动nginx
shell> nginx
# 可通过ps -ef | grep nginx查看nginx是否已启动成功
# 2.停止nginx
shell> nginx -s stop
# 3. 重新启动
shell> nginx -s reload

How to compile and install Nginx

After nginx default configuration is started successfully, it will There are two processes, a main process (daemon process) and a worker process. The main process is responsible for managing the worker process, and the worker process is responsible for processing the user's http request.

6. Configure nginx to start at boot

Add the /usr/bin/nginx command to the /etc/rc.d/rc.local file. The rc.local file will be executed when the system starts. However, centos7 recommends writing the startup service as a service description file and adding it to the system service, so rc.local does not have execution permissions by default, and you need to add execution permissions to it.

shell> vim /etc/rc.d/rc.local
# 添加如下参数
/usr/bin/nginx

shell> chmod +x /etc/rc.d/rc.local

The above is the detailed content of How to compile and install Nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete