Reverse proxy are really useful for accessing services on your server via https
instead of http
. This is also required when using an api, for example, on your website that uses SSL. As it is not allowed to access http
resources from an https
connection.
In this post, I'll show you how to setup a reverse proxy using nginx and secure it with a SSL certificate.
This tutorial presupposes, that you've installed nginx and setup server blocks. If you haven't, here's a guide: https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-debian-10.
Setting up the server file
Firstly, we'll want to create a file name after the service your trying to reverse proxy, for example: reverse-proxy.conf
. To do that, type: nano reverse-proxy.conf
or vim reverse-proxy.conf
if you know how to use vim.
Then insert this basic file:
Now enter these command, to create a symbolic link for the file reverse-proxy.conf
:
Restart nginx:
And voila, you've created a reverse proxy making localhost:8080
available at proxy.example.com
.
Creating and installing the SSL certificate
To be able to access the reverse proxy via https
we'll have to create a SSL certificate using certbot.
I've created a comprehensive tutorial on how to create a certificate using certbot:
Then:
If I have helped you, consider signing up for free to get access to all my guides and my newsletter.