- read

Use Nginx as Reverse Proxy

Harry@StartQuick Tech 28

Use Nginx as Reverse Proxy

This article uses Grafana server as an example to show how Nginx is configured as Reverse Proxy with https redirect

Harry@StartQuick Tech
Level Up Coding
Published in
3 min read5 hours ago


We built a Grafana Server following the standard procedure on an Amazon EC2 instance with Ubuntu 22.04. Then we set up the HTTPs based on the what Grafana suggested.

Finally, we are blocked by this.

We can use HTTPs but we have to use the port 3000 to access the website instead of port 443 as we don’t want to give Grafana with root user privileged.

Then Nginx jumped in.

Nginx can be used as a reverse proxy server. A reverse proxy is also a server that sits between client devices and web servers. It forwards the client requests to the web servers and returns the server’s responses to the clients.

Let’s go through what the Nginx Configuration looks like.

monitor.startquick.tech is a domain for demostration only.

server {
listen 80;
listen [::]:80;
server_name monitor.startquick.tech;
return 301 https://$host$request_uri;

server {
server_name monitor.startquick.tech;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/monitor.startquick.tech/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/monitor.startquick.tech/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot