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

Simple usage example of vue recursive component

Preface I believe many students are already famil...

isPrototypeOf Function in JavaScript

Table of contents 1. isPrototypeOf() Example 1, O...

Echarts implements switching different X-axes in one graph (example code)

Rendering If you want to achieve the effect shown...

Super detailed teaching on how to upgrade the version of MySQL

Table of contents 1. Introduction 2. Back up the ...

MySQL trigger detailed explanation and simple example

MySQL trigger simple example grammar CREATE TRIGG...

A brief discussion on the binary family of JS

Table of contents Overview Blob Blob in Action Bl...

Open the Windows server port (take port 8080 as an example)

What is a Port? The ports we usually refer to are...

Understanding JSON (JavaScript Object Notation) in one article

Table of contents JSON appears Json structure Jso...

Install MySQL (including utf8) using Docker on Windows/Mac

Table of contents 1. Docker installation on Mac 2...

Detailed explanation of the use of various MySQL indexes

1. Slow query log 1.1 MySQL log types Logs are us...

JS realizes the automatic playback effect of pictures

This article shares the specific code of JS to ac...

Vue implements a simple shopping cart example

This article example shares the specific code of ...

Use of Linux cal command

1. Command Introduction The cal (calendar) comman...