nginx reverse proxy Letsencrypt server block works, but does not display my website. Solutions?

November 4, 2016 100 views
Nginx Ubuntu

I followed this tutorial: [https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04](http://) in order get ssl https for my website.

My original nginx reverse-proxy server block successfully displayed my webpage when visiting gentrydemchak.com.

server {
    listen 80;
    listen [::]:80;

    server_name gentrydemchak.com www.gentrydemchak.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

The new server block doesn't throw any errors, and Qualys SSL Labs Report even gave the encryption an A+ rating. but rather than showing my website it displays the nginx welcome page. The server block suggested by the tutorial that i'm using is below:

server {
    listen 443 ssl;

    server_name gentrydemchak.com www.gentrydemchak.com;

    ssl_certificate /etc/letsencrypt/live/gentrydemchak.com/fullc$
    ssl_certificate_key /etc/letsencrypt/live/gentrydemchak.com/p$
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-G$
    ssl_session_timeout 1d;
    ssl_stapling on;
    ssl_session_cache shared:SSL:50m;
    ssl_stapling_verify on;
    add_header Strict-Transport-Security max-age=15768000;

    location ~ /\.well-known/acme-challenge {
        root /root/portfolio/public;
    }

    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

Why is it not serving my website? Is my website in the wrong directory? Is the proxy setup wrong? Am I missing something else entirely?

1 Answer

The first thing that jumps out at me is that your configuration is missing a closing }. Not sure if that's the case in the file on your server or was just a mistake in copy/pasting it here.

Below you can find the configuraiton I am personally using on one of my droplets to do a proxy_pass configuration with a LetsEncrypt generated certificate.

server {

        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        ssl_certificate /etc/letsencrypt/live/dply.co/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/dply.co/privkey.pem;

        server_name _;

        location ~ /.well-known {
                allow all;
        }

        location / {
        proxy_pass http://localhost:4567;
        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;
    }

}

Hope that helps!

  • Didn't seem to work for me, I get a 502 bad gateway message. I'll try running through the tutorial again to see if I missed something...

  • I'm wondering if this has something to do with my web-root path?

    from the tutorial:

    "You will also want look up what your document root is set to by searching for the root directive, as the path is required to use the Webroot plugin. If you're using the default configuration file, the root will be /usr/share/nginx/html."

    Is the document root path where I'm storing my server / web files? I'm not currently storing them under /usr/share/nginx/html, but should they be there instead??

Have another answer? Share your knowledge.