<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://book.ghanim.no/index.php?action=history&amp;feed=atom&amp;title=HomeLab%2FNGINX_SSL_Reverse_Proxy</id>
	<title>HomeLab/NGINX SSL Reverse Proxy - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://book.ghanim.no/index.php?action=history&amp;feed=atom&amp;title=HomeLab%2FNGINX_SSL_Reverse_Proxy"/>
	<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=HomeLab/NGINX_SSL_Reverse_Proxy&amp;action=history"/>
	<updated>2026-04-21T15:20:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://book.ghanim.no/index.php?title=HomeLab/NGINX_SSL_Reverse_Proxy&amp;diff=1122&amp;oldid=prev</id>
		<title>imported&gt;Aghanim at 04:18, 16 October 2020</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=HomeLab/NGINX_SSL_Reverse_Proxy&amp;diff=1122&amp;oldid=prev"/>
		<updated>2020-10-16T04:18:31Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Prerequisite&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Ubuntu 18.04* nginx running* A domain - Example.com* Let&amp;#039;s Encrypt certificate&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this blog post we will configure your website and securing it with SSL using NGINX as a reverse proxy, forwarding traffic to your backend web server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the sake of simplicity lets that you are you are running wordpress website with IP &amp;#039;&amp;#039;&amp;#039;192.168.1.100 &amp;#039;&amp;#039;&amp;#039;and nginx reverse proxy with IP &amp;#039;&amp;#039;&amp;#039;192.168.1.200&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you enter http://192.168.1.216 in your browser you will open up your website. That works OK in a local enviroment, but if you&amp;#039;re going to publicy expose your website to the internet you&amp;#039;re going to have to use a domain and preferably a reverse proxy. When a request is made to your website, it will be forwarded to your reverse proxy. The reverse proxy will terminate the traffic to 192.168.1.100.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Why use a reverse proxy&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A reverse proxy sits in front the web server and will forward visitors (client request) to that web server. It increases security because you won&amp;#039;t expose your backend web server to internet. You can configure the reverse proxy to forward request to multiple backend serverse, thus increasing the anonymity of your network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Configuring NGINX and generate an SSL certificate ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the sites-available directory in /etc/nginx create a conf file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
sudo vim example.com&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here you will type in the instructions for NGINX and where to forward request to example.com. But before we do that we have to generate a certificate. Let&amp;#039;s Encrypt is free and easy to use with certbot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Generate a certificate using this command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
certbot -d example.com --manual --preferred-challenges dns certonly&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Certbot will generate an ACME challenge that you will have to paste in your public DNS. Create a TXT record and paste the ACME challenge that certbot provided you. Wait up to five minutes before you continue so the TXT record can propagate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If succesfull your certficate will be located in:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/etc/letsencrypt/live/example.com&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember to renew your certificate. Let&amp;#039;s encrypt certificate are valid for 3 month. You can use this command to renew a certificate. I will create a new blog post on how you can create a grafana dashboard to monitor your SSL certificate and setting up email alerts. But thats for later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Stop nginx service&lt;br /&gt;
service nginx stop&lt;br /&gt;
&lt;br /&gt;
# Run certbot renew&lt;br /&gt;
certbot -d example.domain.net --standalone --renew-by-default certonly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Start nginx service&lt;br /&gt;
service nginx start&lt;br /&gt;
&lt;br /&gt;
#####&lt;br /&gt;
# If your domain don&amp;#039;t have an A record in a public DNS you have to use this command and paste the ACME challenge in your public DNS&lt;br /&gt;
certbot -d example.domain.net --manual --preferred-challenges dns certonly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, back to nginx. Open up the conf file you created in sites-available and paste in this content. Edit example.com with your domain. Edit ssl_certificate and ssl_certificate_key so they point to the correct directory. Certbot provided you with the directories when you generated the certificate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
server {&lt;br /&gt;
    if ($host = example.com) {&lt;br /&gt;
        return 301 https://$host$request_uri;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
        listen 80 ;&lt;br /&gt;
        listen [::]:80 ;&lt;br /&gt;
&lt;br /&gt;
        server_name example.com www.example.com;&lt;br /&gt;
&lt;br /&gt;
        location / {&lt;br /&gt;
                # First attempt to serve request as file, then&lt;br /&gt;
                # as directory, then fall back to displaying a 404.&lt;br /&gt;
                try_files $uri $uri/ =404;&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
map $http_upgrade $connection_upgrade {&lt;br /&gt;
        default upgrade;&lt;br /&gt;
        &amp;#039;&amp;#039;      close;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# HTTPS Server&lt;br /&gt;
server {&lt;br /&gt;
    listen 443 ssl;&lt;br /&gt;
    server_name example.com;&lt;br /&gt;
&lt;br /&gt;
    # You can increase the limit if your need to.&lt;br /&gt;
    client_max_body_size 200M;&lt;br /&gt;
&lt;br /&gt;
    error_log /var/log/nginx/example.access.log;&lt;br /&gt;
&lt;br /&gt;
    ssl on;&lt;br /&gt;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;&lt;br /&gt;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;&lt;br /&gt;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE&lt;br /&gt;
    ssl_session_timeout 1d;&lt;br /&gt;
    ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions&lt;br /&gt;
    ssl_session_tickets off;&lt;br /&gt;
&lt;br /&gt;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;&lt;br /&gt;
    ssl_prefer_server_ciphers off;&lt;br /&gt;
&lt;br /&gt;
    ssl_stapling on;&lt;br /&gt;
    ssl_stapling_verify on;&lt;br /&gt;
&lt;br /&gt;
    location / {&lt;br /&gt;
        proxy_pass http://192.168.1.100;&lt;br /&gt;
        proxy_http_version 1.1;&lt;br /&gt;
        proxy_set_header Upgrade $http_upgrade;&lt;br /&gt;
        proxy_set_header Connection &amp;quot;upgrade&amp;quot;;&lt;br /&gt;
        proxy_set_header Host $host;&lt;br /&gt;
&lt;br /&gt;
        proxy_set_header X-Real-IP $remote_addr;&lt;br /&gt;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;&lt;br /&gt;
        proxy_set_header X-Forwarded-Proto https;&lt;br /&gt;
        proxy_set_header X-Nginx-Proxy true;&lt;br /&gt;
&lt;br /&gt;
        proxy_redirect off;&lt;br /&gt;
        auth_basic off;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will have to create a symlink to etc/nginx/sites-enabled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Verify that the syntax is correct and reload nginx service.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
nginx -t&lt;br /&gt;
&lt;br /&gt;
##nginx: the configuration file /etc/nginx/nginx.conf syntax is ok&lt;br /&gt;
##nginx: configuration file /etc/nginx/nginx.conf test is successful&lt;br /&gt;
&lt;br /&gt;
service nginx restart&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Create an A record in your public DNS ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Port forward 443 on your router so that the outside world can talk to your reverse proxy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then you have to create an A record in your public DNS which points to your public IP address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, visit your website from outside your local network. Your website now have a green lock and works fine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Last few words ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to test your SSL configuration you can use this website [https://www.ssllabs.com/ssltest/]. It will give you a rating based on these attributes; Certificate, Protocl Support, Key Exchange and Cipher Strength. You can then determin how you want to increase security further.&lt;br /&gt;
&lt;br /&gt;
[[Category:HomeLab]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Aghanim</name></author>
	</entry>
</feed>