Installing Nginx on Linux

1. Ubuntu 22.04

1.1 Installing

1
2
apt update
apt install nginx

1.2 Checking status

1
systemctl status nginx

1.3 Managing the Nginx Process

stop

1
systemctl stop nginx

start

1
systemctl start nginx

restart

1
systemctl restart nginx

reload

If you are only making configuration changes, Nginx can often reload without dropping connections.

1
systemctl reload nginx

enable

To re-enable the service to start up at boot, you can type:

1
systemctl enable nginx

2. CentOS

2.1 Adding the EPEL Software Repository

To add the CentOS 7 EPEL repository, first connect to your CentOS 7 machine via SSH, then use the yum command to install the extended package repository:

1
yum install epel-release

You’ll be prompted to verify that you want to install the software. Type y then ENTER to continue.

Next, you’ll install the actual nginx software package.

2.2 Installing Nginx

Now that the EPEL repository is installed on your server, install Nginx using the following yum command:

1
yum install nginx

2.3 Starting Nginx

1
systemctl start nginx

You can check the status of the service with systemctl status:

1
systemctl status nginx

3. Common

Exploring and Configuring Nginx

If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.

Default Server Root

The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /etc/nginx/conf.d/default.conf.

Server Block Configuration

Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started.

Nginx Global Configuration

The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.


Installing Nginx on Linux
https://www.hardyhu.cn/2022/02/13/Installing-Nginx-on-Linux/
Author
John Doe
Posted on
February 13, 2022
Licensed under