Configure Nginx with HTTPS on a Linux VM when using Cloudflare as proxy

EthanBennett-5484 0 Reputation points
2025-06-09T15:19:25.0866667+00:00

I'd like to get an Nginx server running on a Linux VM (hosted on Azure), and I’m routing traffic through Cloudflare for DNS and proxy. Now I’m looking to properly set up HTTPS, but I’m a bit unsure about the best approach when Cloudflare is in the middle.

Here’s what I’m trying to achieve:

  • Serve the site over HTTPS
  • Use Cloudflare for SSL offloading and DDoS protection
  • Make sure the connection between Cloudflare and my VM is encrypted too (end-to-end)

Now I’m stuck with:

  • How to setup Nginx on Linux VM properly?
  • And if anyone has a clean Nginx config example for this kind of setup, that would be super helpful.

Appreciate any guidance or best practices you’ve picked up from doing this before.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Nikhil Duserla 7,935 Reputation points Microsoft External Staff Moderator
    2025-06-09T17:33:53.32+00:00

    Hello @Ethan Bennett,

    sudo apt update

    sudo apt install nginx

    Adjusting the Firewall- sudo ufw app list

    You should get a listing of the application profiles:

    OutputAvailable applications:

    Nginx Full

    Nginx HTTP

    Nginx HTTPS

    OpenSSH

    sudo ufw allow 'Nginx HTTPS'

    sudo ufw status

    systemctl status nginx

    Install Certbot and it’s Nginx plugin with apt: sudo apt install certbot python3-certbot-nginx

    To check, open the configuration file for your domain using nano or your favorite text editor: sudo nano /etc/nginx/sites-available/example.com

    Find the existing server_name line. It should look like this:

    ...

    server_name example.com www.example.com;

    ...

    sudo nginx -t

    sudo systemctl reload nginx

    sudo ufw status

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

    If you have any further queries, do let us know.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.