Beginner’s Guide to NGINX Configuration Files

hera is the complete guide on how to host any technical school push-down storage on an Ubuntu machine. here, I ’ ve covered all the aspects like front-end host, back-end host with invert proxy along with visualize serving route. This article would be your one discontinue for the complete deployment at output or development environment. thus, let ’ s get started…

Prerequisites

Before we get started with this guide, you should have a regular, non-root user with sudo privileges configured on your server. once you have an account available, log in as your non-root exploiter to begin .

Step 1: Install nginx

Nginx is available in Ubuntu ’ south nonpayment repositories, so the initiation is rather aboveboard.

This would be our foremost interaction with the apt packaging system in this session. We would update our local package index ; so that, we have access to the most recent software listings. then we can install nginx using following instruction

 sudo apt-get update 
sudo apt-get install nginx

After accepting the procedure, apt-get will install Nginx and any compulsory dependencies to your server .

Step 2: Manage the NGINX Process

now that you have your web server up and running, we can go over some basic management commands. To stop your web server

 sudo systemctl blockage nginx

To start the web waiter when it is stopped

 sudo systemctl start nginx

To stop and then start the service again

 sudo systemctl restart nginx

If you are just making shape changes, NGINX can much reload without dropping connections. To do this, this command can be used

 sudo systemctl reload nginx

By nonpayment, NGINX is configured to start automatically when the server boots. If this is not what you want, you can disable this behavior by typing :

 sudo systemctl disable nginx

To re-enable the service to start up at boot

 sudo systemctl enable nginx

To test your config file

 sudo nginx -t

Step 3: Get Familiar with Important NGINX Files and Directories

so once you get to know how to manage the service itself, you should take a few minutes to familiarize yourself with a few important directories and files. Content

  • /var/www/html: The actual web content, which by default only consists of the default Nginx page you saw earlier, is served out of the /var/www/html directory. This can be changed by altering NGINX configuration files.

Server Configuration

  • /etc/nginx: The NGINX configuration directory. All of the Nginx configuration files reside here.
  • /etc/nginx/nginx.conf: The main NGINX configuration file. This can be modified to make changes to the NGINX global configuration.
  • /etc/nginx/sites-available/: The directory where per-site “server blocks” can be stored. NGINX will not use the configuration files found in this directory unless they are linked to the sites-enabled directory (see below). Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory.
  • /etc/nginx/sites-enabled/: The directory where enabled per-site “server blocks” are stored. Typically, these are created by linking to configuration files found in the sites-available directory.
  • /etc/nginx/snippets: This directory contains configuration fragments that can be included elsewhere in the NGINX configuration. Potentially repeatable configuration segments are good candidates for refactoring into snippets.

Server Logs

  • /var/log/nginx/access.log: Every request to your web server is recorded in this log fil unless and until NGINX is configured to do otherwise.
  • /var/log/nginx/error.log: Every NGINX error will be recorded in this log only.

What we have learn so far …

immediately that you have your vane server installed, you have many options for the type of subject to serve and the technologies you want to use to create a richer experience. To verify hit your public address on the browser and blind should look like this .NGINX Ubuntu setup

Configure NGINX to serve your website

You ’ ll need to tell NGINX about your web site and how to serve it. cadmium into /etc/nginx/. This is where the NGINX configuration files are located. The two directories we are concerned in are 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.

now, certificate of deposit into /etc/nginx/sites-enabled and edit default option charge using nano or six as per your choice to follow :

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

The above code is for :

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

now, if you are about to restart NGINX you should see your web site !

 sudo systemctl restart nginx

Configure NGINX to serve your backend

You ’ ll need to tell NGINX about your web site and how to serve it. cadmium into /etc/nginx/. This is where the NGINX configuration files are located. The two directories we are matter to in are 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.

immediately, compact disk into /etc/nginx/sites-enabled and edit default file using nano or united states virgin islands as per your choice to postdate :


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
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;
}

} server { listen 80 default_server ; listen [ : : ] :80 default_server ; root /var/www/html ; index index.html ; server_name _ ; localization / { try_files $ uri $ uri/ =404 ; placement /api/ { proxy_pass hypertext transfer protocol : //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 above code means

  • On /api route back-end can be accessed which is link to out local-host process in port 8080

If you have gone through the entire blog, you might have understood everything on how to install nginx and configure it for your custom. The web log has besides given you data about creating reverse proxy and creating redirects. You can besides visit nginx.org to know more about how to install and use the same .

Configure NGINX to serve your Image folder

cadmium into /etc/nginx/sites-enabled and edit default file using nano or six as per your choice to trace :


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
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;
} server { listen 80 default_server ; listen [ : : ] :80 default_server ; solution /var/www/html ; index index.html ; server_name _ ; location / { try_files $ uri $ uri/ =404 ; location /api/ { proxy_pass hypertext transfer protocol : //localhost:8080/ proxy_http_version 1.1 ; proxy_set_header Upgrade $ http_upgrade ; proxy_set_header Connection 'upgrade ' ; proxy_set_header Host $ master of ceremonies ; proxy_cache_bypass $ http_upgrade ;
localization /images {
alias uploads/images/ ;
}
}

What does above code means

  • On /images route images can be accessed which is link to instance folder uploads/images. It will point to all images in images folder.

Conclusion

If you have gone through the entire web log, you might have understood everything on how to install nginx and configure it for your custom. The web log has besides given you data about creating reverse proxy and creating redirects. You can besides visit nginx.org to know more about how to install and use the same. Connect with Adrixus to know more .

beginning : https://thefartiste.com
Category : Tech

About admin

I am the owner of the website thefartiste.com, my purpose is to bring all the most useful information to users.

Check Also

articlewriting1

Manage participants in a zoom meeting webinar

Call the people who attend the meet as follows Alternate host host Who scheduled the …

Leave a Reply

Your email address will not be published.