Home > Operation and Maintenance > Nginx > How to install nginx under Linux

How to install nginx under Linux

PHPz
Release: 2023-05-16 19:48:07
forward
4238 people have browsed it

Installing dependencies

yum install gcc
yum install pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel
Copy after login

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

Download nginx tar package

//进入/usr/local目录
cd /usr/local
//创建一个文件夹nginx
mkdir nginx
//进入nginx文件夹
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
//解压tar包
tar -xvf nginx-1.13.7.tar.g
Copy after login

Install nginx

//进入nginx目录
cd /usr/local/nginx
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install
Copy after login

Start nginx

/usr/local/nginx/sbin/nginx
Copy after login

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

As long as there is no response on the console after execution, visit the address of the server where you installed nginx in the browser, you can see the nginx welcome interface, and the nginx installation is complete

How to install nginx under Linux

Start nginx

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

Linux modify the path /usr/local/nginx/conf/nginx.conf, and the installation directory \conf\nginx.conf under windows.

Change the port to 8090 and localhost to your server IP address. (Success is in sight!!)

How to install nginx under Linux

Start nginx

netstat -ano|grep 80
Copy after login

If the execution result cannot be found, ignore the previous step (it must be started with sudo under ubuntu , otherwise it can only run in the foreground)

nginx restart, shutdown, start

Startup

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
Copy after login

Stop

There are three ways to stop nginx:

Stop calmly

1. Check the process number

[root@linuxserver ~]# ps -ef|grep nginx
Copy after login
Copy after login

How to install nginx under Linux

2. Kill the process

[root@linuxserver ~]# kill -quit 2072
Copy after login

How to install nginx under Linux

Quick stop

1. Check the process number

[root@linuxserver ~]# ps -ef|grep nginx
Copy after login
Copy after login

How to install nginx under Linux

2. Kill the process

[root@linuxserver ~]# kill -term 2132
或 [root@linuxserver ~]# kill -int 2132
Copy after login

How to install nginx under Linux

Force stop

[root@linuxserver ~]# pkill -9 nginx
Copy after login

Restart

1. Verify that the nginx configuration file is correct

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

See the following display nginx.conf syntax is ok

nginx.conf test is successful

Indicates that the configuration file is correct!

How to install nginx under Linux

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

How to install nginx under Linux

2. Restart the nginx service

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

How to install nginx under Linux

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

How to install nginx under Linux

If you start nginx, the following error will be reported:

How to install nginx under Linux

Probably means: the port address has been used. It is very likely that the nginx service process is stuck, causing port 80 to be occupied. The default port of nginx is 80. Execute the command to query the port occupancy

netstat -ntpl
Copy after login

How to install nginx under Linux

Yes See that port 80 is occupied by nginx. At this time, execute kill -9 5347 (5347 can be seen from the picture above as the pid of this process) to kill the process. Just restart nginx. If you still cannot start nginx, you can only go to Baidu based on the error message and deal with specific problems on a case-by-case basis.

The above is the detailed content of How to install nginx 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