Let's Encrypt Not Working (Grav, NGINX, Ubuntu 16.04.2)

July 12, 2017 559 views
Let's Encrypt Nginx Ubuntu 16.04

Hi,

I'm having an issue getting Let's Encrypt to work on my current droplet (Nginx on Ubuntu 16.04.2 with the Grav CMS). I've followed the tutorial (https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04) and once I figured out that installing Grav had moved the root, I experienced no errors.

The problem is, it just isn't working. My site still returns http and errors at https. Is there something I'm missing? My /etc/nginx/sites-available/default file is pasted below. Could Grav be overwriting something?

Any help appreciated.

Thanks,

Ben

server {
listen 80;
listen [::]:80;
servername ben-johnston.co.uk www.ben-johnston.co.uk;
return 301 https://www.ben-johnston.co.uk$request
uri;
}

server{
# SSL configuration
#
listen 443 ssl http2 defaultserver;
listen [::]:443 ssl http2 default
server;
include snippets/ssl-www.ben-johnston.co.uk.conf;
include snippets/ssl-params.conf;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on sslciphers 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;
server
name www.ben-johnston.co.uk;

    root /home/grav/www/html;


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

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

    server_name www.ben-johnston.co.uk;

    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:
# fastcgipass 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;
    #}

}

2 Answers

Hi @BenJohnston

Let's make sure the configurations in /etc/nginx/sites-available/ are the same as the ones in /etc/nginx/sites-enabled/.
Please run these two commands and post the result:

ls -ls /etc/nginx/sites-available/

ls -ls /etc/nginx/sites-enabled/

And let's see the status of your firewall, so we know if it's active or not:

sudo ufw status

PS - use the </> button the comment editor to encapsulate as code, which is easier to read and it doesn't lose formatting.

  • Hi @hansen. Thanks so much for getting back to me.

    The results of those commands are:

    ls -ls /etc/nginx/sites-available/
    
    total 12
    4 -rw-r--r-- 1 root root 2411 Jul  9 13:16 default
    4 -rw-r--r-- 1 root root 2168 Jul  9 12:44 default.bak
    4 -rw-r--r-- 1 root root 1397 Jul  9 08:24 grav
    
    ls -ls /etc/nginx/sites-enabled/
    total 0
    0 lrwxrwxrwx 1 root root 23 Apr  7 16:35 grav -> ../sites-available/grav
    

    The firewall is currently disabled.

    Thanks,

    Ben

    • @BenJohnston

      Okay, let's delete the two unused configurations - make sure you have backup:

      rm /etc/nginx/sites-available/default
      rm /etc/nginx/sites-available/default.bak
      

      And then show the content of /etc/nginx/sites-enabled/grav, which is your only active configuration, so this is the one holding all the goodies :)

OK, so here's what we've got in there. I'm guessing I need to add the SSL configuration files into this file?

server {
    #listen 80;
    index index.html index.php;

    ## Begin - Server Info
    root /home/grav/www/html;
    server_name 138.68.130.152;
    ## End - Server Info

    ## Begin - Index
    # for subfolders, simply adjust the rewrite:
    # to use `/subfolder/index.php`
    location / {
        try_files $uri $uri/ /index.php?_url=$uri;

    }

    ## End - Index

    ## Begin - PHP
    location ~ \.php$ {
        # Choose either a socket or TCP/IP address
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        # fastcgi_pass 127.0.0.1:9000;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }
    ## End - PHP

    ## Begin - Security
    # deny all direct access for these folders
    location ~* /(.git|cache|bin|logs|backups)/.*$ { return 403; }
    # deny running scripts inside core system folders
    location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
    # deny running scripts inside user folder
    location ~* /user/.*\.(txt|md|yaml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
    # deny access to specific files in the root folder
    location ~ /(LICENSE|composer.lock|composer.json|nginx.conf|web.config|htaccess.txt|\.htaccess) { return 403; }
    ## End - Security



}

Thanks again.

  • @BenJohnston
    Correct. And modify the server_name as well, since it's only an IP right now.
    If you got problems, then just let me know by using the @ to notify me.

Have another answer? Share your knowledge.