Warner Cloud: How to configure nginx server under ubuntu

Configuring Nginx server on Ubuntu operating system involves the following steps. Here I will provide a basic configuration example that you can modify and customize according to your needs.

Install Nginx : Open a terminal and enter the following command to install Nginx:

sudo apt update

sudo apt install nginx

Start the Nginx service : After the installation is complete, use the following command to start the Nginx service:

sudo systemctl start nginx

If you want to automatically start Nginx when the system starts, you can run:

sudo systemctl enable nginx

Configuration file directory : Nginx’s main configuration file is located in /etc/nginx/nginx.conf. It references other configuration files, such as the site configuration file.

Create a site configuration file : Create a new configuration file in the /etc/nginx/sites-available/ directory and name it your domain name or application. For example, create a profile named example.com:

sudo nano /etc/nginx/sites-available/example.com

Configuring the site : In the site configuration file, you need to define server blocks to configure the behavior of the site. Here's a simple example:

 

In this example configuration, Nginx will listen on port 80 and forward requests from the domain names example.com and www.example.com to the /var/www/example.com directory, displaying the index.html file.

Enable sites : After creating the site configuration file, you need to create a symbolic link in the /etc/nginx/sites-enabled/ directory to link the site configuration file to the enabled site. The following commands can be used:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Check the configuration and restart Nginx : Use the following command to check whether the Nginx configuration is correct:

sudo nginx -t

If there are no errors, you can reload the Nginx configuration:

sudo systemctl reload nginx

The above steps provide a basic Nginx configuration example. You can add more instructions and settings in the configuration file according to your own needs, such as SSL configuration, proxy settings, etc. After completing the configuration, test whether your Nginx server is working properly by accessing your domain name or IP address.

Guess you like

Origin blog.csdn.net/YOKEhn/article/details/132430837
Recommended