Generic setup of a https nginx/Apache reverse proxy
Assume we have a web site engine (web server, blog, shellinabox, you name it) running in your private network at ip 10.10.10.10 port 3500, serving http.
We want to expose this local/intern web service to the internet, without giving the internet access to our local machine. We want to use the https-protocol and proxy via web server nginx or Apache, using a (sub)domain that we own, let’s assume for simplifying reasons that this is https://sub.example.com
.
Here we look at two very basic proxy setups to realize this task.
nginx
So, given that nginx is already installed, for the proxy functionality, at the server that serves https://sub.example.com
, we configure a nginx site as /etc/nginx/sites-available/sub.example.com
:
Next, we install certbot
for obtaining SSL certificates for our server:
Now we have to make our website public, in order that certbot
can obtain a certificate from Let’s Encrypt via the ACME protocol. We do that by making the site available:
After that, we have to reload the nginx configuration:
Now we should be able to access our server via http://sub.example.com
which is internally served by http://10.10.10.10:3500
.
To obtain the certificate, we now run
This will provide our server with a Let’s Encrypt certificate, create and enable a new nginx ssl configuration /etc/nginx/sites-available/sub.example.com-ssl
, and modify the original config enable SSL. The automatically changed config file should now read like
That’s it! Now we have a local/intern web service exposed to the internet using the https-protocol via nginx.
Apache
Again we assume that the web server itself is already installed. So we configure at the server that serves https://sub.example.com
an Apache site as /etc/apache2/sites-available/sub.example.com.conf
:
For the proxy configuration to work, we want to be sure to have proxy functionality enabled:
Next, we install certbot
for obtaining SSL certificates for our server:
Now we have to make our website public, in order that certbot
can obtain a certificate from Let’s Encrypt via the ACME protocol. We do that by making the site available:
After that, we have to restart Apache:
Now we should be able to access our server via http://sub.example.com
which is internally served by http://10.10.10.10:3500
.
To obtain the certificate, we now run
This will provide our server with a Let’s Encrypt certificate, create and enable a new Apache ssl configuration /etc/apache/sites-available/sub.example.com-le-ssl.conf
, and modify the original config to redirect from http to https. The automatically created config file should read like
That’s it! Now we have a local/intern web service exposed to the internet using the https-protocol via Apache.