How to Configurate NGINX web server | DevOps Services

Опубликовано: 27 Май 2026
на канале: Dedicated DevOps
216
3

How to install NGINX web server on Ubuntu
   • How to Install NGINX Web Server On Ubuntu ...  

Hope you see our last video, In this video, we are learning about,
Configure NGINX to serve your site:

You'll have to enlighten NGINX regarding your site and how to serve it.
cd into /etc/nginx/. This is where the NGINX setup documents are found.

The two registries we are keen on are destinations accessible and locales empowered.

sites-available contains individual configuration files for all of your possible static websites.
sites-enabled contains links to the configuration files that NGINX will actually read and run.

Now, cd into /etc/nginx/sites-enabled and edit the default file using nano or vi as per your choice to the following:

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}

This code is for:

-Deliver files from the folder /var/www/html or this can be a path to your index.html.
-The main page is called index.html.
-Requests, that are requesting should be served by this server block.

If you want to restart NGINX you should see your site!

sudo systemctl restart nginx

Configure NGINX to serve your backend:

You need to tell NGINX about the website and how to serve it.

cd into /etc/nginx/. This is where the NGINX configuration files are found.

The two directories are interested in sites-available and sites-enabled.

-sites-available contains individual configuration files for all of your possible static websites.
-sites-enabled contains links to the configuration files that NGINX will actually read and run.

cd into /etc/nginx/sites-enabled and edit default file using nano or vi as your choice to following:

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_pass http://localhost:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

}

What does this code mean:

-On /api route back-end can be accessed which is connected to our local-host process in port 8080

Configure NGINX to serve your Image folder:

cd into /etc/nginx/sites-enabled and edit default file using nano or vi as your choice to following:

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_pass http://localhost:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /images {
alias uploads/images/;
}
}

What does above code means:

-On /images route images can be accessed which is connect to the folder uploads/images. It will take all images in images folder.

Hope you have understood everything about How to install the NGINX web server on Ubuntu and how to configure it.
   • How to Install NGINX Web Server On Ubuntu ...