nginx-proxy / acme-companion

Automated ACME SSL certificate generation for nginx-proxy
MIT License
7.38k stars 820 forks source link

Can not init api (ACME, lets encrypt) #938

Closed TBoonX closed 2 years ago

TBoonX commented 2 years ago

Bug description

The ACME process does not start because it has issues with the API (lets encrypt).

acme-companion image version

Info: running acme-companion version v2.2.0-7-g3137221

nginx-proxy's Docker configuration

version: '3.8'
services:
  proxy-server: # Reverse proxy
    image: nginxproxy/nginx-proxy
    restart: always
    ports:
        - "80:80"
        - "443:443"
    networks:
        - sub
    volumes:
        - /var/run/docker.sock:/tmp/docker.sock:ro
        - certs:/etc/nginx/certs:ro
        - vhost:/etc/nginx/vhost.d
        - html:/usr/share/nginx/html
        - ./filesize.conf:/etc/nginx/conf.d/filesize.conf
    labels:
        com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: ""

    logging:
        driver: "json-file"
        options:
            max-file: "3"
            max-size: "10m"
  proxy-letsencrypt: # Let's encrypt part which interacts with webserver and docker engine
    image: nginxproxy/acme-companion
    restart: always
    networks:
        - sub
    environment:
        - DEFAULT_EMAIL=${LE_DEFAULT_EMAIL}
        - NGINX_PROXY_CONTAINER=proxy-server
    volumes:
        - /var/run/docker.sock:/var/run/docker.sock:ro
        - certs:/etc/nginx/certs:rw
        - vhost:/etc/nginx/vhost.d
        - html:/usr/share/nginx/html
        - acme:/etc/acme.sh
    logging:
        driver: "json-file"
        options:
            max-file: "1"
            max-size: "1m"

volumes:
    certs:
    vhost:
    html:
    acme:

networks:
    sub:

rendered nginx configuration

Please provide the rendered nginx configuration:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  10240;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
daemon off;

# configuration file /etc/nginx/mime.types:

types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/xml                                         xml;
    image/gif                                        gif;
    image/jpeg                                       jpeg jpg;
    application/javascript                           js;
    application/atom+xml                             atom;
    application/rss+xml                              rss;

    text/mathml                                      mml;
    text/plain                                       txt;
    text/vnd.sun.j2me.app-descriptor                 jad;
    text/vnd.wap.wml                                 wml;
    text/x-component                                 htc;

    image/avif                                       avif;
    image/png                                        png;
    image/svg+xml                                    svg svgz;
    image/tiff                                       tif tiff;
    image/vnd.wap.wbmp                               wbmp;
    image/webp                                       webp;
    image/x-icon                                     ico;
    image/x-jng                                      jng;
    image/x-ms-bmp                                   bmp;

    font/woff                                        woff;
    font/woff2                                       woff2;

    application/java-archive                         jar war ear;
    application/json                                 json;
    application/mac-binhex40                         hqx;
    application/msword                               doc;
    application/pdf                                  pdf;
    application/postscript                           ps eps ai;
    application/rtf                                  rtf;
    application/vnd.apple.mpegurl                    m3u8;
    application/vnd.google-earth.kml+xml             kml;
    application/vnd.google-earth.kmz                 kmz;
    application/vnd.ms-excel                         xls;
    application/vnd.ms-fontobject                    eot;
    application/vnd.ms-powerpoint                    ppt;
    application/vnd.oasis.opendocument.graphics      odg;
    application/vnd.oasis.opendocument.presentation  odp;
    application/vnd.oasis.opendocument.spreadsheet   ods;
    application/vnd.oasis.opendocument.text          odt;
    application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                     pptx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                     xlsx;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                     docx;
    application/vnd.wap.wmlc                         wmlc;
    application/wasm                                 wasm;
    application/x-7z-compressed                      7z;
    application/x-cocoa                              cco;
    application/x-java-archive-diff                  jardiff;
    application/x-java-jnlp-file                     jnlp;
    application/x-makeself                           run;
    application/x-perl                               pl pm;
    application/x-pilot                              prc pdb;
    application/x-rar-compressed                     rar;
    application/x-redhat-package-manager             rpm;
    application/x-sea                                sea;
    application/x-shockwave-flash                    swf;
    application/x-stuffit                            sit;
    application/x-tcl                                tcl tk;
    application/x-x509-ca-cert                       der pem crt;
    application/x-xpinstall                          xpi;
    application/xhtml+xml                            xhtml;
    application/xspf+xml                             xspf;
    application/zip                                  zip;

    application/octet-stream                         bin exe dll;
    application/octet-stream                         deb;
    application/octet-stream                         dmg;
    application/octet-stream                         iso img;
    application/octet-stream                         msi msp msm;

    audio/midi                                       mid midi kar;
    audio/mpeg                                       mp3;
    audio/ogg                                        ogg;
    audio/x-m4a                                      m4a;
    audio/x-realaudio                                ra;

    video/3gpp                                       3gpp 3gp;
    video/mp2t                                       ts;
    video/mp4                                        mp4;
    video/mpeg                                       mpeg mpg;
    video/quicktime                                  mov;
    video/webm                                       webm;
    video/x-flv                                      flv;
    video/x-m4v                                      m4v;
    video/x-mng                                      mng;
    video/x-ms-asf                                   asx asf;
    video/x-ms-wmv                                   wmv;
    video/x-msvideo                                  avi;
}

# configuration file /etc/nginx/conf.d/default.conf:
# nginx-proxy version : 1.0.0-8-g0442ed9
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  default $http_x_forwarded_proto;
  ''      $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
  default $http_x_forwarded_port;
  ''      $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
  default upgrade;
  '' close;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header based on $proxy_x_forwarded_proto
map $proxy_x_forwarded_proto $proxy_x_forwarded_ssl {
  default off;
  https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent" '
                 '"$upstream_addr"';
access_log off;
        ssl_protocols TLSv1.2 TLSv1.3;
        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';
        ssl_prefer_server_ciphers off;
error_log /dev/stderr;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
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 $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
proxy_set_header X-Original-URI $request_uri;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    server_tokens off;
    listen 80;
    access_log /var/log/nginx/access.log vhost;
    return 503;
}
server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    server_tokens off;
    listen 443 ssl http2;
    access_log /var/log/nginx/access.log vhost;
    return 503;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;
    ssl_certificate /etc/nginx/certs/default.crt;
    ssl_certificate_key /etc/nginx/certs/default.key;
}
    # tasks.coypu.org
    upstream tasks.coypu.org {
        # Cannot connect to network 'redmine_db' of this container
        # Cannot connect to network 'redmine_smtp' of this container
        ## Can be connected with "reverseproxy_sub" network
        # redmine_redmine_1
        server 192.168.0.4:3000;
    }
server {
    server_name tasks.coypu.org;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
location / {
        proxy_pass http://tasks.coypu.org;
}
}
server {
    server_name tasks.coypu.org;
    listen 443 ssl http2 ;
    access_log /var/log/nginx/access.log vhost;
    return 500;
    ssl_certificate /etc/nginx/certs/default.crt;
    ssl_certificate_key /etc/nginx/certs/default.key;
}

# configuration file /etc/nginx/conf.d/filesize.conf:
client_max_body_size 50M;

Containers logs

Companion:

Info: running acme-companion version v2.2.0-7-g3137221
Generating a RSA private key
.................................................................................................++++
...++++
writing new private key to '/etc/nginx/certs/default.key.new'
-----
Reloading nginx proxy (bef8952eecb051329d16d832c099240b37320a9daf617967bd8ec92aafe37ce4)...
2022/03/28 14:28:11 Generated '/etc/nginx/conf.d/default.conf' from 6 containers
2022/03/28 14:28:11 [notice] 109#109: signal process started
Info: a default key and certificate have been created at /etc/nginx/certs/default.key and /etc/nginx/certs/default.crt.
Info: Setting up 4096 bits RFC7919 Diffie-Hellman group...
Reloading nginx proxy (bef8952eecb051329d16d832c099240b37320a9daf617967bd8ec92aafe37ce4)...
2022/03/28 14:28:11 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification ''
2022/03/28 14:28:11 [notice] 153#153: signal process started
2022/03/28 14:28:11 Generated '/app/letsencrypt_service_data' from 6 containers
2022/03/28 14:28:11 Running '/app/signal_le_service'
2022/03/28 14:28:11 Watching docker events
2022/03/28 14:28:11 Contents of /app/letsencrypt_service_data did not change. Skipping notification '/app/signal_le_service'
[Mon Mar 28 14:30:22 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:30:22 UTC 2022] Can not init api for: https://acme-v02.api.letsencrypt.org/directory.
[Mon Mar 28 14:30:22 UTC 2022] Create account key ok.
[Mon Mar 28 14:30:22 UTC 2022] Registering account: https://acme-v02.api.letsencrypt.org/directory
[Mon Mar 28 14:32:33 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:32:33 UTC 2022] Could not get nonce, let's try again.
[Mon Mar 28 14:34:46 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:34:46 UTC 2022] Could not get nonce, let's try again.
[Mon Mar 28 14:36:59 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:36:59 UTC 2022] Could not get nonce, let's try again.
[Mon Mar 28 14:39:12 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:39:12 UTC 2022] Could not get nonce, let's try again.
[Mon Mar 28 14:41:25 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:41:25 UTC 2022] Could not get nonce, let's try again.
[Mon Mar 28 14:43:38 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:43:38 UTC 2022] Could not get nonce, let's try again.
[Mon Mar 28 14:45:51 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:45:51 UTC 2022] Could not get nonce, let's try again.
[Mon Mar 28 14:48:05 UTC 2022] Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: 28
[Mon Mar 28 14:48:05 UTC 2022] Could not get nonce, let's try again.

Nginx:

Info: running nginx-proxy version 1.0.0-8-g0442ed9
Setting up DH Parameters..
forego      | starting dockergen.1 on port 5000
forego      | starting nginx.1 on port 5100
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: using the "epoll" event method
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: nginx/1.21.6
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: OS: Linux 5.4.0-104-generic
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: start worker processes
...
dockergen.1 | 2022/03/28 14:28:10 Generated '/etc/nginx/conf.d/default.conf' from 6 containers
dockergen.1 | 2022/03/28 14:28:10 Running 'nginx -s reload'
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: signal 1 (SIGHUP) received from 58, reconfiguring
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: reconfiguring
dockergen.1 | 2022/03/28 14:28:10 Watching docker events
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: using the "epoll" event method
nginx.1     | 2022/03/28 14:28:10 [notice] 20#20: start worker processes
...
dockergen.1 | 2022/03/28 14:28:10 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
...
nginx.1     | tasks.coypu.org 192.168.0.1 - - [28/Mar/2022:14:49:30 +0000] "GET / HTTP/1.1" 302 135 "-" "Go-http-client/1.1" "192.168.0.4:3000"
nginx.1     | tasks.coypu.org 192.168.0.1 - - [28/Mar/2022:14:49:30 +0000] "GET /login?back_url=http%3A%2F%2Ftasks.coypu.org%2F HTTP/1.1" 200 6841 "http://159.69.72.186" "Go-http-client/1.1" "192.168.0.4:3000"

Docker host

bradpurchase commented 2 years ago

Seeing this too. Did you ever figure it out?

TBoonX commented 2 years ago

I did, thanks for reminding. I solved it by deactivating the ufw, recreating the docker network (sub) used by the proxy and activate ufw again.

NilsBaumgartner1994 commented 1 year ago

Facing the same problem currently. UFW is inactive.