How to install nginx under Linux

How to install nginx under Linux

Nginx is developed in C language and is recommended to run on Linux. Of course, you can also install the Windows version.

Install Dependencies

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

When installing these 4 dependencies, there will be some questions in the middle, just enter Y

Download the nginx tarball

//Enter the /usr/local directory cd /usr/local
//Create a folder nginx
mkdir nginx
//Enter the nginx folder cd nginx
//Download the tarball wget http://nginx.org/download/nginx-1.13.7.tar.gz
//Unzip the tar package tar -xvf nginx-1.13.7.tar.g

Install nginx

//Enter the nginx directory cd /usr/local/nginx
//Execute the command ./configure
//Execute the make command make
//Execute the make install command make install

Start nginx

/usr/local/nginx/sbin/nginx

Note: This path is based on your own installation path, just change it to your own path.

After executing the command, there is no response in the console. Visit the address of the nginx server you installed in the browser, and you can see the nginx welcome interface. At this point, nginx is installed.


Start nginx

Because apeache may occupy port 80, try not to modify the apeache port. We choose to modify the nginx port.

In Linux, modify the path /usr/local/nginx/conf/nginx.conf. In Windows, modify the installation directory\conf\nginx.conf.

Change the port to 8090 and localhost to your server IP address. (Success is just around the corner!!)

Start nginx

netstat -ano|grep 80

If no execution results are found, ignore the previous step (Ubuntu must be started with sudo, otherwise it can only run in the foreground)

nginx restart, shutdown, and startup

start up

Startup code format: nginx installation directory address -c nginx configuration file address

For example:

[root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

stop

There are three ways to stop nginx:

Stop calmly

1. Check the process number

[root@LinuxServer ~]# ps -ef|grep nginx 

2. Kill the process

[root@LinuxServer ~]# kill -QUIT 2072 

Quick Stop

1. Check the process number

[root@LinuxServer ~]# ps -ef|grep nginx 

2. Kill the process

[root@LinuxServer ~]# kill -TERM 2132
or [root@LinuxServer ~]# kill -INT 2132

Force Stop

[root@LinuxServer ~]# pkill -9 nginx

Restart

1. Verify whether the nginx configuration file is correct

Method 1: Enter the nginx installation directory sbin and enter the command ./nginx -t

The following shows that nginx.conf syntax is ok

nginx.conf test is successful

This indicates that the configuration file is correct!

Method 2: Add -t before the startup command -c

2. Restart Nginx service

Method 1: Enter the nginx executable directory sbin and enter the command ./nginx -s reload

Method 2: Find the current nginx process number, and then enter the command: kill -HUP process number to restart the nginx service

If you start nginx, the following error is reported:


The general meaning is: the port address is already in use. It is very likely that the nginx service process is stuck, resulting in port 80 being occupied. The default port of nginx is 80. Execute the command to check the port occupancy.

netstat -ntpl 


As you can see, port 80 is occupied by nginx. At this time, execute kill -9 5347 (5347 is the PID of this process as shown in the above figure) to kill the process, and then start nginx again.

If you purchased an Alibaba Cloud server and there is no error when starting nginx, but the nginx welcome interface still does not appear when accessing nginx, please read:

https://www.jb51.net/article/159514.htm , you need to set port 80 in the Alibaba Cloud security level group.

If you still cannot start nginx, you can only search Baidu based on the error message and deal with the specific problem specifically.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed process of installing nginx with shell script source code
  • Shell script nginx automation script
  • Detailed explanation of putting common nginx commands into shell scripts
  • Example of implementing nginx self-starting script under centos/rhel
  • Shell script to install Nginx service and customize Nginx version in one click

<<:  MySQL uninstall and install graphic tutorial under Linux

>>:  jQuery plugin to implement minesweeper game (2)

Recommend

Some thoughts and experience sharing on web page (website) design and production

First, before posting! Thanks again to I Want to S...

How to implement Nginx reverse proxy for multiple servers

Nginx reverse proxy multiple servers, which means...

MySQL tutorial thoroughly understands stored procedures

Table of contents 1. Concepts related to stored p...

C# implements MySQL command line backup and recovery

There are many tools available for backing up MyS...

Detailed explanation of the payment function code of the Vue project

1. Alipay method: Alipay method: Click Alipay to ...

How to compare two database table structures in mysql

During the development and debugging process, it ...

Detailed explanation of importing/exporting MySQL data in Docker container

Preface We all know that the import and export of...

Installation and use tutorial of Elasticsearch tool cerebro

Cerebro is an evolution of the Elasticsearch Kopf...

Steps to package and deploy the Vue project to the Apache server

In the development environment, the vue project i...

Overview of time configuration under Linux system

1. Time types are divided into: 1. Network time (...

Summary of MySQL InnoDB architecture

Table of contents introduction 1. Overall archite...

H tags should be used reasonably in web page production

HTML tags have special tags to handle the title of...

Docker container exits after running (how to keep running)

Phenomenon Start the Docker container docker run ...