Knowledge Base

HomepageKnowledge BaseHow to Install Nginx server on Ubuntu and SSL ...

How to Install Nginx server on Ubuntu and SSL setup

  1. Update Your Server

sudo apt update && sudo apt upgrade -y

  1. Install Nginx

Ubuntu’s default repo already includes Nginx.

sudo apt install nginx -y

Check status:

systemctl status nginx

You should see active (running).

  1. Allow Firewall (UFW)

If UFW is enabled:

sudo ufw allow 'Nginx Full'

sudo ufw enable

sudo ufw status

This opens 80 (HTTP) and 443 (HTTPS).

  1. Verify Nginx is Serving Pages

Open browser:

Code

http://your_server_ip

You should see the default Nginx welcome page.

  1. Create Your Website Directory

Example for domain: example.com

sudo mkdir -p /var/www/example.com/html

sudo chown -R $USER:$USER /var/www/example.com/html

sudo chmod -R 755 /var/www/example.com

Add a test file:

nano /var/www/example.com/html/index.html

 

Paste:

Welcome to example.com

  1. Create Nginx Server Block

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

 

Add:

nginx

server {

    listen 80;

    server_name example.com www.example.com;

    root /var/www/example.com/html;

    index index.html;

    location / {

        try_files $uri $uri/ =404;

    }

}

 

Enable it:

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

Disable default site (optional):

sudo rm /etc/nginx/sites-enabled/default

  1. Test Configuration

sudo nginx -t

If OK:

sudo systemctl reload nginx

  1. Enable HTTPS (Let’s Encrypt SSL)

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Run:

sudo certbot --nginx -d example.com -d www.example.com

Auto-renew test:

sudo certbot renew --dry-run

  1. Optional: Reverse Proxy Setup

If you want to proxy to Node.js, Python, PHP-FPM, etc.:

nginx

location / {

    proxy_pass http://127.0.0.1:3000;

    proxy_set_header Host $host;

    proxy_set_header X-Real-IP $remote_addr;

}

Reload:

sudo systemctl reload nginx

 

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(13 times viewed / 0 people found it helpful)

Top