How to configure Nginx on Linux Ubuntu

Nginx is a Open-source web server, High performance and Reverse proxy software. Nginx is handle a large number of concurrent requests and popular for high-traffic websites and web applications.
Nginx can be used as a web server to serve static content such as HTML files, images, videos. ,Also hosted java, PHP, node, react Js application hosted on the Nginx server. It is most of used in a production environments to serve and manage traffic for web application and website.


Step 1 : Install Nginx in Linux ubuntu use the following command

sudo apt update
sudo apt install nginx

Step 2 : Nginx main configuration file is located at /etc/nginx/nginx.conf location.

You can modify this file to configure Nginx as per project or domain requirements. 

Below example configuration that can be added to http section of the nginx.conf file 

server {
    listen 80;
    server_name example.com;
    root /var/www/html/example.com;

    location / {
        index index.html;

This configuration will listen on port 80 for the domain example.com, serve files from the directory /var/www/html/example.com, 

and use index.html file in a add any configuration code.

Step 3 : Configuration completed after Reload the Nginx configuration, you can test if the configuration is valid using the following command:

sudo nginx -t

sudo systemctl reload nginx

If you have any error showing you can show log at /var/log/nginx/error.log to debug the issues.

These are the basic steps to configure Nginx on Ubuntu. Also you can version vise installed Nginx in your system.

Post a Comment