Trying to setup LE Certs for domain with this error

Hi All

Done this quite a few times but it seems ive got something in my configuration file incorrect. I have an application (grafana) working on 192.168.1.3:3000 and want to serve this.

error is:

nsautomate@ihp:/etc/nginx/sites-enabled$ sudo certbot certonly --nginx -d chilcote.nsautomate.com.au
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for chilcote.nsautomate.com.au
Waiting for verification…
Cleaning up challenges
Failed authorization procedure. chilcote.nsautomate.com.au (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://chilcote.nsautomate.com.au/.well-known/acme-challenge/ABzB3x_EUcgFbbjONrNlY4yoxkliyk5MgnkvMFJMj6g [180.150.13.216]: “\r\n404 Not Found\r\n<body bgcolor=“white”>\r\n

404 Not Found

\r\n
”

IMPORTANT NOTES:

My configuration file is:

upstream ihp {

    server 192.168.1.3:3000;

}

server {

    listen 80;
    listen [::]:80;

    server_name chilcote.nsautomate.com.au;

    return 301 https://chilcote.nsautomate.com.au$request_uri;

    server_tokens off; # This hide server version just in case someones needs it for a hack...

}

server {

    listen 443 ssl;
    listen [::]:443 ssl http2;

    server_name chilcote.nsautomate.com.au;
    server_tokens off;

    access_log      /var/log/nginx/chilcote.nsautomate.com.au/access.log;
    error_log       /var/log/nginx/chilcote.nsautomate.com.au/error.log;

    #### SSL Config

#ssl_certificate /etc/letsencrypt/live/chilcote.nsautomate.com.au/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/live/chilcote.nsautomate.com.au/privkey.pem;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:20m;
ssl_session_tickets off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_protocols TLSv1.2 TLSv1.3; # This will affect old Browsers that doesn’t supports new versions of TLS (not SSL ;)).

    ssl_prefer_server_ciphers       on;
    ssl_ecdh_curve          secp384r1;
    ssl_ciphers             'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_stapling            on;
    ssl_stapling_verify     on;

    resolver                        8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout                5s;

    add_header                      Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
    add_header                      X-Frame-Options DENY;
    add_header                      X-Content-Type-Options nosniff;
    add_header                      X-XSS-Protection "1; mode=block";

    #### Compression - Can be disabled anytime but will help externally

    gzip                    on;
    gzip_disable            "msie6";
    gzip_vary                       on;
    gzip_proxied            any;
    gzip_comp_level                 9;
    gzip_buffers            16 8k;
    gzip_http_version               1.1;
    gzip_min_length                 256;
     gzip_types                     text/plain
                            text/css
                            application/json
                            application/javascript
                            application/x-javascript
                            text/xml
                            application/xml
                            application/xml+rss
                            text/javascript
                            application/vnd.ms-fontobject
                            application/x-font-ttf
                            font/opentype
                            image/svg+xml
                            image/x-icon;

  location / {

     proxy_pass                     http://ihp; # Defined on the upstream section
     proxy_set_header               X-Real-IP        $remote_addr;
     proxy_set_header               X-Forwarded-For  $proxy_add_x_forwarded_for;
     proxy_set_header               Host $http_host;
     proxy_set_header               X-Forwarded-SSL on;
     proxy_set_header               X-Forwarded-Proto https;
     proxy_redirect                 default;
     proxy_redirect                 http://$host/ https://$host/;
     proxy_redirect                 http://hostname/ https://$host/;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     proxy_send_timeout 1200s;
     proxy_read_timeout 1200s;
     fastcgi_send_timeout 1200s;
     fastcgi_read_timeout 1200s;

    }

}

Any suggestions as to why this is occuring? Thanks

Visiting chilcote.nsautomate.com.au, I get the default nginx welcome page, rather than the expected 301 redirect.

$ curl -X GET -I chilcote.nsautomate.com.au
HTTP/1.1 200 OK
Server: nginx/1.14.0 (Ubuntu)

This would indicate that the request is arriving to the wrong server (maybe port forwarding is misconfigured on your router?), or you have multiple nginx virtualhosts for that server_name.

This type of misconfiguration would likely cause the Certbot nginx plugin to malfunction.

If you could get nginx in a state where your configured redirect actually works, that would probably solve your Certbot issue as well.

1 Like

Of course! I’m stupid. I’ve got another server running on a different IP/using 443/80

:confused:

Thanks _az

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.