How to install Nginx1.16.0 under linux

王林
Release: 2023-05-17 11:25:06
forward
1238 people have browsed it

Install necessary dependent plug-ins

yum install -y gcc gcc-c++ pcre \
pcre-devel zlib zlib-devel openssl openssl-devel wget
Copy after login

Create a folder and switch to it

mkdir /customer && cd /customer
Copy after login

Download the installation package (Similarly, if you want to install other versions, you can go to the official website link below and select the link for other versions Copy and replace)

wget https://nginx.org/download/nginx-1.16.0.tar.gz
Copy after login

Extract and install

tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx
make && make install
Copy after login

Add global command

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
Copy after login

Test installation

nginx -v

As shown below, the installation is successful:

How to install Nginx1.16.0 under linux

Verify whether the service is started successfully

netstat -ntlp | grep nginx
Copy after login

As follows:

How to install Nginx1.16.0 under linux

Add nginx service

vim /lib/systemd/system/nginx.service
Copy after login

Insert the following content:

[unit]
description=nginx
after=network.target

[service]
type=forking
execstart=/usr/local/nginx/sbin/nginx
execreload=/usr/local/nginx/sbin/nginx -s reload
execstop=/usr/local/nginx/sbin/nginx -s quit
privatetmp=true

[install]
wantedby=multi-user.target
Copy after login

Start nginx as a service

pkill nginx

systemctl start nginx
Copy after login

Check whether the service is started

 systemctl status nginx
 netstat -ntlp | grep nginx
Copy after login

Configure the nginx service to start automatically at boot

systemctl enable nginx
Copy after login

The installation is now complete , the configuration file is at:

vim /usr/local/nginx/conf/nginx.conf
Copy after login

Optional:

The version number of nginx is open by default and can be viewed in the default error page and http response header.

Different versions, especially lower versions of nginx, may have vulnerabilities, so if you don’t want others to obtain the version number, you can choose to hide the version number.

Hide nginx version number

cd /usr/local/nginx/conf
vim nginx.conf
Copy after login

Change the "server_tokens" of the nginx.conf file to "off":

http {
...
server_tokens off;
...
}
Copy after login

Modify fastcgi.conf

##vim fastcgi.conf

Modify the following lines

fastcgi_param server_software nginx/$nginx_version;
# 改为:
fastcgi_param server_software nginx;
Copy after login

Restart nginx

systemctl restart nginx
Copy after login

The above is the detailed content of How to install Nginx1.16.0 under linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!