documentation/assets/js/72.a824f4b4.js

1 line
20 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(window.webpackJsonp=window.webpackJsonp||[]).push([[72],{419:function(e,t,a){"use strict";a.r(t);var s=a(48),n=Object(s.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"creating-ssl-certificates"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#creating-ssl-certificates"}},[e._v("#")]),e._v(" Creating SSL Certificates")]),e._v(" "),a("p",[e._v("This tutorial briefly covers creating new SSL certificates for your panel and wings.")]),e._v(" "),a("tabs",[a("tab",{attrs:{name:"Method 1: Certbot"}},[a("p",[e._v("To begin, we will install certbot, a simple script that automatically renews our certificates and allows much\neasier creation of them. The command below is for Ubuntu distributions, but you can always check "),a("a",{attrs:{href:"https://certbot.eff.org/",target:"_blank",rel:"noopener noreferrer"}},[e._v("Certbot's official\nsite"),a("OutboundLink")],1),e._v(" for installation instructions. We have also included a command below to install certbot's\nNginx/Apache plugin so you won't have to stop your webserver.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sudo")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("apt")]),e._v(" update\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sudo")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("apt")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("install")]),e._v(" -y certbot\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("# Run this if you use Nginx")]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sudo")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("apt")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("install")]),e._v(" -y python3-certbot-nginx\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("# Run this if you use Apache")]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sudo")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("apt")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("install")]),e._v(" -y python3-certbot-apache\n")])])]),a("h2",{attrs:{id:"creating-a-certificate"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-certificate"}},[e._v("#")]),e._v(" Creating a Certificate")]),e._v(" "),a("p",[e._v("After installing the certbot, we need to generate a certificate. There are a couple of ways to do that, but the easiest\nis to use the web server-specific certbot plugin you just installed. For Wings-only machines that don't need a web server, use the standalone or DNS method of the certbot as you don't need a web server for it.")]),e._v(" "),a("p",[e._v("Then, in the command below, you should replace "),a("code",[e._v("example.com")]),e._v(" with the domain you would like to generate a certificate\nfor. When you have multiple domains you would like certificates for, simply add more "),a("code",[e._v("-d anotherdomain.com")]),e._v(" flags to the\ncommand. You can also look into generating a wildcard certificate but that is not covered in this tutorial.")]),e._v(" "),a("p",[e._v("When you are using certbot's Nginx/Apache plugin, you won't need to restart your webserver to have the certificate\napplied assuming that you've already configured the webservers to use SSL as instructed in the "),a("a",{attrs:{href:"https://pterodactyl.io/panel/1.0/webserver_configuration.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("web server configuration step"),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("h3",{attrs:{id:"http-challenge"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#http-challenge"}},[e._v("#")]),e._v(" HTTP challenge")]),e._v(" "),a("p",[e._v("HTTP challenge requires you to expose port 80 for the challenge verification.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("# Nginx")]),e._v("\ncertbot certonly --nginx -d example.com\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("# Apache")]),e._v("\ncertbot certonly --apache -d example.com\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("# Standalone - Use this if neither works. Make sure to stop your webserver first when using this method.")]),e._v("\ncertbot certonly --standalone -d example.com\n")])])]),a("h3",{attrs:{id:"dns-challenge"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#dns-challenge"}},[e._v("#")]),e._v(" DNS challenge")]),e._v(" "),a("p",[e._v("DNS challenge requires you to create a new TXT DNS record to verify domain ownership, instead of having to expose port 80. The instructions are displayed when you run the certbot command below.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[e._v("certbot -d example.com --manual --preferred-challenges dns certonly\n")])])]),a("h3",{attrs:{id:"auto-renewal"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#auto-renewal"}},[e._v("#")]),e._v(" Auto Renewal")]),e._v(" "),a("p",[e._v("You'll also probably want to configure the automatic renewal of certificates to prevent unexpected certificate expirations.\nYou can open crontab with "),a("code",[e._v("sudo crontab -e")]),e._v(" and add the line from below to the bottom of it for attempting renewal every day at 23 (11 PM).")]),e._v(" "),a("p",[e._v("Deploy hook would restart the Nginx service to apply a new certificate when it's renewed successfully. Change "),a("code",[e._v("nginx")]),e._v(" in the restart command to suit your own needs, such as to "),a("code",[e._v("apache")]),e._v(" or "),a("code",[e._v("wings")]),e._v(".")]),e._v(" "),a("p",[e._v("For advanced users, we suggest installing and using "),a("a",{attrs:{href:"https://acme.sh",target:"_blank",rel:"noopener noreferrer"}},[e._v("acme.sh"),a("OutboundLink")],1),e._v("\nwhich provides more options, and is much more powerful than certbot.")]),e._v(" "),a("div",{staticClass:"language-text extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('0 23 * * * certbot renew --quiet --deploy-hook "systemctl restart nginx"\n')])])]),a("h3",{attrs:{id:"troubleshooting"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#troubleshooting"}},[e._v("#")]),e._v(" Troubleshooting")]),e._v(" "),a("p",[e._v("If you get an "),a("code",[e._v("Insecure Connection")]),e._v(" or SSL/TLS related error when trying to access your panel or wings, the certificate has likely expired.\nThis can be easily fixed by renewing the SSL certificate, although using the command "),a("code",[e._v("certbot renew")]),e._v(" might not do the job if port 80 is in use, as it'll return errors like: "),a("code",[e._v("Error: Attempting to renew cert (domain) from /etc/letsencrypt/renew/domain.conf produced an unexpected error")]),e._v(".")]),e._v(" "),a("p",[e._v("This will happen especially if you're running Nginx instead of Apache. The solution for this is to use Nginx or Apache plugins with "),a("code",[e._v("--nginx")]),e._v(" and "),a("code",[e._v("--apache")]),e._v(". Alternatively, you can stop Nginx, then renew the certificate, finally restart Nginx. Replace "),a("code",[e._v("nginx")]),e._v(" with your own web server or with "),a("code",[e._v("wings")]),e._v(" should you be renewing the certificate for Wings.")]),e._v(" "),a("p",[e._v("Stop Nginx:")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[e._v("systemctl stop nginx\n")])])]),a("p",[e._v("Renew the certificate:")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[e._v("certbot renew\n")])])]),a("p",[e._v("Once the process has complete, you can restart the Nginx service:")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[e._v("systemctl start nginx\n")])])]),a("p",[e._v("You may also need to restart Wings as not every service is able to automatically apply an updated certificate:")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[e._v("systemctl restart wings\n")])])])]),e._v(" "),a("tab",{attrs:{name:"Method 2: acme.sh (using Cloudflare API)"}},[a("p",[e._v("This is for advanced users, whose server systems do not have access to port 80. The command below is for Ubuntu distributions and CloudFlare API (you may google for other APIs for other DNS providers), but you can always check "),a("a",{attrs:{href:"https://github.com/Neilpang/acme.sh",target:"_blank",rel:"noopener noreferrer"}},[e._v("acme.sh's official site"),a("OutboundLink")],1),e._v(" for installation instructions.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[e._v("curl")]),e._v(" https://get.acme.sh "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("|")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sh")]),e._v("\n")])])]),a("h3",{attrs:{id:"obtaining-cloudflare-api-key"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#obtaining-cloudflare-api-key"}},[e._v("#")]),e._v(" Obtaining CloudFlare API Key")]),e._v(" "),a("p",[e._v('After installing acme.sh, we need to fetch a CloudFlare API key. On Cloudfare\'s website, select your domain, then on the right side, copy your "Zone ID" and "Account ID" then click on "Get your API token", click on "Create Token" > select the template "Edit zone DNS" > select the scope of "Zone Ressources" and then click on "Continue to summary", copy your token.')]),e._v(" "),a("h3",{attrs:{id:"creating-a-certificate-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-certificate-2"}},[e._v("#")]),e._v(" Creating a Certificate")]),e._v(" "),a("p",[e._v("Since the configuration file is based on Certbot, we need to create the folder manually.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sudo")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("mkdir")]),e._v(" -p /etc/letsencrypt/live/example.com\n")])])]),a("p",[e._v("After installing acme.sh and obtaining CloudFlare API key, we need to then generate a certificate. First input the CloudFlare API credentials.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[e._v("export")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[e._v("CF_Token")]),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token string"}},[e._v('"Your_CloudFlare_API_Key"')]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[e._v("export")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[e._v("CF_Account_ID")]),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token string"}},[e._v('"Your_CloudFlare_Account_ID"')]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[e._v("export")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[e._v("CF_Zone_ID")]),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token string"}},[e._v('"Your_CloudFlare_Zone_ID"')]),e._v("\n\n")])])]),a("p",[e._v("Then create the certificate.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[e._v("acme.sh --issue --dns dns_cf -d "),a("span",{pre:!0,attrs:{class:"token string"}},[e._v('"example.com"')]),e._v(" --server letsencrypt "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("\\")]),e._v("\n--key-file /etc/letsencrypt/live/example.com/privkey.pem "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("\\")]),e._v("\n--fullchain-file /etc/letsencrypt/live/example.com/fullchain.pem\n")])])]),a("h3",{attrs:{id:"auto-renewal-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#auto-renewal-2"}},[e._v("#")]),e._v(" Auto Renewal")]),e._v(" "),a("p",[e._v("After running the script for the first time, it will be added to the crontab automatically. You may edit the auto renewal interval by editing the crontab.")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sudo")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("crontab")]),e._v(" -e\n")])])])]),e._v(" "),a("tab",{attrs:{name:"Method 3: Caddy (using Cloudflare API)"}},[a("p",[e._v("This is for advanced users, who are running Cloudflare in proxy mode or do not have access to port "),a("code",[e._v("80")]),e._v(".")]),e._v(" "),a("h3",{attrs:{id:"installing-caddy-with-cloudflare-dns-plugin"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#installing-caddy-with-cloudflare-dns-plugin"}},[e._v("#")]),e._v(" Installing Caddy with Cloudflare DNS plugin")]),e._v(" "),a("p",[e._v("Caddy does not come by default with Cloudflare DNS plugin, you need to install it yourself.")]),e._v(" "),a("p",[e._v("There are two main methods:")]),e._v(" "),a("ol",[a("li",[e._v("Using "),a("code",[e._v("xcaddy")]),e._v(" - CLI tool to build your own Caddy build")]),e._v(" "),a("li",[e._v("Downloading prebuilt binary from "),a("a",{attrs:{href:"https://caddyserver.com/download",target:"_blank",rel:"noopener noreferrer"}},[e._v("Caddy's download page"),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("li",[e._v("Using Ansible to download and install Caddy with plugins. See "),a("a",{attrs:{href:"https://github.com/caddy-ansible/caddy-ansible",target:"_blank",rel:"noopener noreferrer"}},[e._v("caddy-ansible"),a("OutboundLink")],1)])]),e._v(" "),a("h4",{attrs:{id:"build-caddy-using-xcaddy-on-your-server"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#build-caddy-using-xcaddy-on-your-server"}},[e._v("#")]),e._v(" Build Caddy using "),a("code",[e._v("xcaddy")]),e._v(" on your server")]),e._v(" "),a("p",[e._v("Please refer to "),a("a",{attrs:{href:"https://caddyserver.com/docs/build#xcaddy",target:"_blank",rel:"noopener noreferrer"}},[e._v("Caddy docs on building Caddy"),a("OutboundLink")],1),e._v(".")]),e._v(" "),a("h3",{attrs:{id:"obtaining-cloudflare-api-token"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#obtaining-cloudflare-api-token"}},[e._v("#")]),e._v(" Obtaining CloudFlare API Token")]),e._v(" "),a("p",[e._v('After installing acme.sh, we need to fetch a CloudFlare API key. Please make sure that a DNS record (A or CNAME record) is pointing to your target node, and set the cloud to grey (bypassing CloudFlare proxy). Then go to My Profile > API keys and on Global API Key subtab, click on "view", enter your CloudFlare password, and copy the API key to clipboard.')]),e._v(" "),a("p",[e._v('After install Caddy with Cloudflare DNS plugin, we need to fetch a Cloudflare API token. Please make sure that a DNS record (A or CNAME record) is pointing at your target node. Then go to My Profile > API Tokens and on API Tokens click "Create Token". Create API Token > API token templates, at the end of line with "Edit zone DNS", click "Use template". Under '),a("strong",[e._v("Zone Resources")]),e._v(', select your DNS zone for which you wish to create the API token, click "Continue to summary". Review the API token summary and click "Create Token". And finally copy the API token to clipboard.')]),e._v(" "),a("h3",{attrs:{id:"reconfiguring-caddy-to-use-cloudflare-dns-for-obtaining-certificates"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#reconfiguring-caddy-to-use-cloudflare-dns-for-obtaining-certificates"}},[e._v("#")]),e._v(" Reconfiguring Caddy to use Cloudflare DNS for obtaining certificates")]),e._v(" "),a("p",[e._v("Create an environment variable file (like "),a("code",[e._v(".env")]),e._v("), keep in mind that this file contains secrets and should not be accessed by public.")]),e._v(" "),a("p",[e._v("We recommend that you create the secret file in the following location: "),a("code",[e._v("/etc/caddy/.secrets.env")]),e._v(".")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[e._v("CLOUDFLARE_API_TOKEN")]),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("=")]),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("your cloudflare api token"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n")])])]),a("p",[e._v("For security reasons, we recommend setting permissions to "),a("code",[e._v("0600")]),e._v(" (only owner can read or write to the file).")]),e._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("# Set ownership of the `.secrets.env` file to `caddy` system user")]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("chown")]),e._v(" caddy:caddy /etc/caddy/.secrets.env\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[e._v("# Set read-write permissions only to owner - the `caddy` system user")]),e._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("chmod")]),e._v(" 0600 /etc/caddy/.secrets.env\n")])])]),a("p",[e._v("Modify the systemd unit file, to load environment variables from file (add "),a("code",[e._v("--envfile /etc/caddy/.secrets.env")]),e._v(" flag to "),a("code",[e._v("ExecStart")]),e._v("), the default systemd unit file location is "),a("code",[e._v("/etc/systemd/system/caddy.service")]),e._v(":")]),e._v(" "),a("div",{staticClass:"language-unit extra-class"},[a("div",{staticClass:"highlight-lines"},[a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("div",{staticClass:"highlighted"},[e._v(" ")]),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br"),a("br")]),a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("[Unit]\nDescription=Caddy\nDocumentation=https://caddyserver.com/docs/\nAfter=network.target network-online.target\nRequires=network-online.target\n\n[Service]\nType=notify\nUser=caddy\nGroup=caddy\nExecStart=/usr/bin/caddy run --environ --envfile /etc/caddy/.secrets.env --config /etc/caddy/Caddyfile\nExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile\nTimeoutStopSec=5s\nLimitNOFILE=1048576\nLimitNPROC=512\nPrivateTmp=true\nProtectSystem=full\nAmbientCapabilities=CAP_NET_BIND_SERVICE\n\n[Install]\nWantedBy=multi-user.target\n")])])]),a("p",[e._v("You can add a "),a("code",[e._v("tls")]),e._v(" block to your "),a("code",[e._v("Caddyfile")]),e._v(", under the "),a("code",[e._v("<domain>")]),e._v(" block of your panel configuration, the Caddy config file location is "),a("code",[e._v("/etc/caddy/Caddyfile")]),e._v(":")]),e._v(" "),a("div",{staticClass:"language-caddyfile extra-class"},[a("div",{staticClass:"highlight-lines"},[a("br"),a("br"),a("br"),a("br"),a("div",{staticClass:"highlighted"},[e._v(" ")]),a("div",{staticClass:"highlighted"},[e._v(" ")]),a("div",{staticClass:"highlighted"},[e._v(" ")]),a("br")]),a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("<domain> {\n # ...\n\n tls {\n dns cloudflare {env.CLOUDFLARE_API_TOKEN}\n }\n}\n")])])])])],1)],1)}),[],!1,null,null,null);t.default=n.exports}}]);