DEV Community

chenchih
chenchih

Posted on

NGINX HTTP Server

Let me show you how to setup HTTP the most easy way using NGINX. I used to setup HTTP with Apache or other related tool, but it seem like NGINX is much easier.

NGINX HTTP Server

Below are the basic configure version:

  • OS: ubuntu 20.04

Step 1. Install Nginx:

sudo apt install nginx -y

Step2 Verify Nginx is Running show statusd

sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

3.Adjust Firewall (UFW - if active):

sudo ufw allow 'Nginx HTTP'
sudo ufw reload
Enter fullscreen mode Exit fullscreen mode

4. Test Nginx from your browser (Optional but Recommended):

please navigate your web browser using your local IP it should occur index page

http://172.21.201.250
or 
http://127.0.0.1
Enter fullscreen mode Exit fullscreen mode

Step 5. set permission

sudo chmod 644 /var/www/html/
Enter fullscreen mode Exit fullscreen mode

Step 6. Edit ngix configure to allow index to show like file management

sudo nano /etc/nginx/sites-available/default
    location / {
        try_files $uri $uri/ =404;
        autoindex on; # <--- Add this line
    }
Enter fullscreen mode Exit fullscreen mode

Step 7. Test Nginx configuration for syntax errors:

when you change your configure you can verify whether it will occur error or not.

sudo nginx -t
Enter fullscreen mode Exit fullscreen mode

Step 8. Reload Nginx to apply changes

sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Step 9. Change your index into file management

Default will have index.nginx-debian.html in /var/www/html directory. Make sure there's no .html file in directory, it will treat any html file as index. I will rename html file ext into bk. You no need to delete it, maybe in future you want to use again.

sudo mv /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.bak
Enter fullscreen mode Exit fullscreen mode

Step 10. Access to your site will show like File Management, display all your files or folder.

Top comments (0)