{"id":950,"date":"2020-03-24T08:55:37","date_gmt":"2020-03-24T06:55:37","guid":{"rendered":"https:\/\/www.rocworks.at\/wordpress\/?p=950"},"modified":"2020-09-15T21:50:39","modified_gmt":"2020-09-15T19:50:39","slug":"nginx-certbot-letsencrypt-via-docker","status":"publish","type":"post","link":"https:\/\/www.rocworks.at\/wordpress\/?p=950","title":{"rendered":"Nginx &#038; Certbot (Letsencrypt) via Docker&#8230;"},"content":{"rendered":"\n<p>Initially you have to init the certbot and get the certificate manually.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Directories used:\n\/var\/www \n\/var\/www\/certbot # handshake sites from certbot\n\/etc\/letsencrypt # certificates are stored here<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Initialize Certbot:\ndocker run --rm -ti \\\n  -v \/var\/www:\/var\/www \\\n  -v \/etc\/letsencrypt:\/etc\/letsencrypt \\\ncertbot\/certbot certonly --webroot -w \/var\/www\/certbot -d &lt;yor-domain-name> --email your.email@something.com <\/code><\/pre>\n\n\n\n<p>The letsencrypt and the www directory must be mounted on both containers. Certbot will check the certificates every 12h and nginx must reload the configuration periodically.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  nginx:\n    image: nginx:1.17.8\n    ports:\n      - 80:80\n      - 443:443\n    volumes:\n      - \/var\/www:\/var\/www\n      - \/etc\/nginx.conf:\/etc\/nginx\/nginx.conf\n      - \/etc\/letsencrypt:\/etc\/letsencrypt\n    command: \"\/bin\/sh -c 'while :; do sleep 6h &amp; wait $${!}; nginx -s reload; done &amp; nginx -g \\\"daemon off;\\\"'\"\n\n  certbot:\n    image: certbot\/certbot\n    restart: unless-stopped\n    volumes:\n      - \/var\/www:\/var\/www\n      - \/etc\/letsencrypt:\/etc\/letsencrypt\n    entrypoint: \"\/bin\/sh -c 'trap exit TERM; while :; do certbot renew --webroot -w \/var\/www\/certbot; sleep 12h &amp; wait $${1}; done;'\"<\/code><\/pre>\n\n\n\n<p>Nginx must be configured to publish the certbots well-known sites for the handshake and your sites must be configured to use the certificates from letsencrypt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    server {\n        listen 80;\n        server_name &lt;your-domain-name>;\n        server_tokens off;\n        location \/.well-known\/acme-challenge\/ {\n            root \/var\/www\/certbot;\n        }\n\n        location \/ {\n            return 301 https:\/\/$host$request_uri;\n        }\n    }\n\n    server {\n        listen 443 ssl;\n        server_name vcm.winccoa.at;\n\n        ssl_certificate     \/etc\/letsencrypt\/live\/&lt;your-domain-name>\/fullchain.pem;\n        ssl_certificate_key \/etc\/letsencrypt\/live\/&lt;your-domain-name>\/privkey.pem;\n\n        root \/var\/www;\n        index index.html;\n\n        location \/ {\n            try_files $uri $uri\/ =404;\n        }<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Initially you have to init the certbot and get the certificate manually. The letsencrypt and the www directory must be mounted on both containers. Certbot will check the certificates every 12h and nginx must reload the configuration periodically. Nginx must be configured to publish the certbots well-known sites for the handshake and your sites must &hellip; <a href=\"https:\/\/www.rocworks.at\/wordpress\/?p=950\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Nginx &#038; Certbot (Letsencrypt) via Docker&#8230;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,34,12],"tags":[],"class_list":["post-950","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-docker","category-linux"],"_links":{"self":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=950"}],"version-history":[{"count":6,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/950\/revisions"}],"predecessor-version":[{"id":981,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/950\/revisions\/981"}],"wp:attachment":[{"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocworks.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}