Default "Welcome to nginx" Page Shown After Installing Let's Encrypt Certbot

July 3, 2018 129 views
Django Nginx Let's Encrypt Ubuntu 16.04

I've set up a custom server with Django and Nginx on Ubuntu 16.04, and it was working just fine. But then I installed Certbot following this tutorial, and the now-HTTPS domain, instead of showing the Django website, shows the default "Welcome to nginx!" page. I've searched for solutions here and in other places, as well as tried tinkering with the settings myself, but nothing worked so far. Has anyone encountered this problem before, and do you know how to possibly fix it?

I'm providing the sites-available/default and sites-available/projectname files in case the problem lies in them.

default:

# Default server configuration
#
server {
        # listen 80 default_server;
        # listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name mydomain.com www.mydomain.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/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


}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

projectname:

server {
    listen 443 ssl;
    server_name mydomain.com www.mydomain.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/lasmelan/projectname;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/lasmelan/projectname/projectname.sock;
    }
}
2 Answers

Why is.

root /home/lasmelan/projectname;

Inside a location block?

Contact me, I can fix it

The problem turned out to be that "server_name mydomain.com www.mydomain.com;" shouldn't have been in sites-available/default, only in sites-available/projectname.

Have another answer? Share your knowledge.