Detailed tutorial on installing Nginx 1.16.0 under Linux

Detailed tutorial on installing Nginx 1.16.0 under Linux

Because I have been tinkering with Linux recently, I wanted to install a new version of nginx. I looked for a tutorial but couldn't find the corresponding one. After a little tinkering, I finally successfully installed the latest version.

The server environment is centos, the following are the detailed steps:

Install necessary dependency plugins

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 (if you want to install other versions, you can go to the official website link below and select the link of other versions to copy and replace)

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

Unzip and install

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

Adding global commands

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

Test the installation

nginx -V

As shown below, the installation is successful:

Verify that the service is started successfully

netstat -ntlp | grep nginx

as follows:

Add nginx service

vim /lib/systemd/system/nginx.service

Insert the following into:

[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 nginx service to start automatically at boot

systemctl enable nginx

Now the installation is complete, the configuration file is:

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

Optional:

The version number of nginx is turned on 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" in the nginx.conf file to "off":

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

Modify fastcgi.conf again

vim fastcgi.conf

Modify the following line

fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
# Change to:
fastcgi_param SERVER_SOFTWARE nginx;

Restart nginx

systemctl restart nginx

Hide version number completed

Summarize

The above is a detailed tutorial on how to install Nginx 1.16.0 under Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

You may also be interested in:
  • How to install nginx under Linux
  • Example of how to install nginx to a specified directory
  • How to install Nginx in CentOS7 and configure automatic startup
  • How to install Nginx source code
  • How to install and start nginx in Linux
  • Nginx installation, startup, restart and shutdown on MAC
  • Tutorial on installing lnmp using yum on centos7 (linux+nginx+php7.1+mysql5.7)
  • Nginx installation detailed tutorial

<<:  The use and difference between JavaScript pseudo-array and array

>>:  A brief discussion of 3 new features worth noting in TypeScript 3.7

Recommend

CSS3 realizes the effect of triangle continuous enlargement

1. CSS3 triangle continues to zoom in special eff...

mysql-8.0.16 winx64 latest installation tutorial with pictures and text

I just started learning about databases recently....

Tomcat class loader implementation method and example code

Tomcat defines multiple ClassLoaders internally s...

CSS to achieve the effect of rotating flip card animation

The css animation of the rotating flip effect, th...

Detailed steps for smooth transition from MySQL to MariaDB

1. Introduction to MariaDB and MySQL 1. Introduct...

Zabbix configuration DingTalk alarm function implementation code

need Configuring DingTalk alarms in Zabbix is ​​s...

HTML code to add quantity badge to message button

HTML code: <a onclick="goMessage();"...

Detailed explanation of persistent storage of redis under docker

In this chapter, we will start to operate redis i...

Two ways to declare private variables in JavaScript

Preface JavaScript is not like other languages ​​...

js to achieve simple product screening function

This article example shares the specific code of ...

Solve the Linux Tensorflow2.0 installation problem

conda update conda pip install tf-nightly-gpu-2.0...

Some problems that may be caused by inconsistent MySQL encoding

Stored procedures and coding In MySQL stored proc...