Home  >  Article  >  Operation and Maintenance  >  How to install Nginx1.16.0 under linux

How to install Nginx1.16.0 under linux

王林
王林forward
2023-05-17 11:25:061239browse

Install necessary dependent plug-ins

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

Create a folder and switch to it

mkdir /customer && cd /customer

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

Extract and install

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

Add global command

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

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

As follows:

How to install Nginx1.16.0 under linux

Add nginx service

vim /lib/systemd/system/nginx.service

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

Start nginx as a service

pkill nginx

systemctl start nginx

Check whether the service is started

 systemctl status nginx
 netstat -ntlp | grep nginx

Configure the nginx service to start automatically at boot

systemctl enable nginx

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

vim /usr/local/nginx/conf/nginx.conf

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

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

http {
...
server_tokens off;
...
}

Modify fastcgi.conf

##vim fastcgi.conf

Modify the following lines

fastcgi_param server_software nginx/$nginx_version;
# 改为:
fastcgi_param server_software nginx;

Restart nginx

systemctl restart nginx

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!

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