lets_encrypt.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. ***************
  2. Let's Encrypt
  3. ***************
  4. Let's Encrypt is one of the most recent and widely used form of free SSL security and supports wildcard DNS. You can use Let's Encrypt with your FusionPBX install and WebRTC like `Verto Communicator`_.
  5. Dehydrated (Recommended)
  6. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7. FusionPBX has an option to easily and quickly install SSL with Let's Encrypt using **letsencrypt.sh** With this script you can choose either to request an SSL certificate with wildcard (*.domain.tld) or hostnames (domain.tld).
  8. The letsencrypt.sh will do the following:
  9. * Download `dehydrated <https://github.com/lukas2511/dehydrated>`_.
  10. * Request an SSL certificate from `Let's Encrypt <https://letsencrypt.com>`_.
  11. * Configure NGINX to use the SSL certificate.
  12. * Combine and place the SSL certificate in the proper `FreeSWITCH <https://freeswitch.org/confluence/display/FREESWITCH/FreeSWITCH+Explained>`_ directory for using TLS.
  13. * Test and make sure the SSL cert works and outputs if successful.
  14. Using letsencrypt.sh
  15. ---------------------
  16. With letsencrypt.sh you have the choice of creating an SSL certificate for a single domain (domain.tld), multiple subdomains (sub.domain.tld, sub1.domain.tld, etc.domain.tld) or wildcard (*.domain.tld). The easy way however is using the hostname method.
  17. Hostname
  18. ~~~~~~~~~~
  19. To create a hostname or multiple hostname SSL certificate go to:
  20. ::
  21. cd /usr/src/fusionpbx-install.sh/debian/resources/
  22. Then execute the script.
  23. ::
  24. ./letsencrypt.sh
  25. You should then see and follow the prompts.
  26. ::
  27. Domain Name: domain.tld
  28. Email Address: [email protected]
  29. After that, you should see the following output.
  30. ::
  31. Cloning into 'dehydrated'...
  32. remote: Counting objects: 1914, done.
  33. remote: Total 1914 (delta 0), reused 0 (delta 0), pack-reused 1914
  34. Receiving objects: 100% (1914/1914), 616.01 KiB | 0 bytes/s, done.
  35. Resolving deltas: 100% (1199/1199), done.
  36. # INFO: Using main config file /etc/dehydrated/config
  37. + Generating account key...
  38. + Registering account key with ACME server...
  39. + Done!
  40. # INFO: Using main config file /etc/dehydrated/config
  41. + Creating chain cache directory /etc/dehydrated/chains
  42. Processing domain.tld
  43. + Creating new directory /etc/dehydrated/certs/domain.tld ...
  44. + Signing domains...
  45. + Generating private key...
  46. + Generating signing request...
  47. + Requesting new certificate order from CA...
  48. + Received 1 authorizations URLs from the CA
  49. + Handling authorization for domain.tld
  50. + 1 pending challenge(s)
  51. + Deploying challenge tokens...
  52. + Responding to challenge for domain.tld authorization...
  53. + Challenge is valid!
  54. + Cleaning challenge tokens...
  55. + Requesting certificate...
  56. + Checking certificate...
  57. + Done!
  58. + Creating fullchain.pem...
  59. + Done!
  60. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  61. nginx: configuration file /etc/nginx/nginx.conf test is successful
  62. Wildcard
  63. ~~~~~~~~~~~
  64. To create a wildcard SSL certificate go to:
  65. ::
  66. cd /usr/src/fusionpbx-install.sh/debian/resources/
  67. Then execute the script.
  68. ::
  69. ./letsencrypt.sh
  70. You should then see and follow the prompts:
  71. ::
  72. Domain Name: *.domain.tld
  73. Email Address: [email protected]
  74. ::
  75. Cloning into 'dns-01-manual'...
  76. remote: Counting objects: 9, done.
  77. remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 9
  78. Unpacking objects: 100% (9/9), done.
  79. Checking connectivity... done.
  80. # INFO: Using main config file /etc/dehydrated/config
  81. + Account already registered!
  82. # INFO: Using main config file /etc/dehydrated/config
  83. Processing *.domain.tld
  84. + Checking domain name(s) of existing cert... changed!
  85. + Domain name(s) are not matching!
  86. + Names in old certificate: domain.tld
  87. + Configured names: *.domain.tld
  88. + Forcing renew.
  89. + Checking expire date of existing cert...
  90. + Valid till Nov 19 16:08:32 2018 GMT (Longer than 30 days). Ignoring because renew was forced!
  91. + Signing domains...
  92. + Generating private key...
  93. + Generating signing request...
  94. + Requesting new certificate order from CA...
  95. + Received 1 authorizations URLs from the CA
  96. + Handling authorization for domain.tld
  97. + 1 pending challenge(s)
  98. + Deploying challenge tokens...
  99. .. note::
  100. When you define the txt record with your domain registrar be sure to use the output of the script you are running and not what is in this example.
  101. ::
  102. Add the following to the zone definition of domain.tld:
  103. _acme-challenge.domain.tld. IN TXT "PY7ttk6no_5eG7WtAbO6qs5-NzA-Kigko375omKc0nw"
  104. **Press enter to continue...**
  105. ::
  106. + Responding to challenge for domain.tld authorization...
  107. + Challenge is valid!
  108. + Cleaning challenge tokens...
  109. ::
  110. Now you can remove the following from the zone definition of domain.tld:
  111. _acme-challenge.domain.tld. IN TXT "PY7ttk6no_5eG7WtAbO6qs5-NzA-Kigko375omKc0nw"
  112. **Press enter to continue...**
  113. ::
  114. + Requesting certificate...
  115. + Checking certificate...
  116. + Done!
  117. + Creating fullchain.pem...
  118. deploy_cert()
  119. Done!
  120. **done**
  121. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  122. nginx: configuration file /etc/nginx/nginx.conf test is successful
  123. .. tip::
  124. Use the dig command to check that the txt record is correct. dig -t txt _acme-challenge.domain.tld
  125. Output should show:
  126. ;; ANSWER SECTION:
  127. _acme-challenge.domain.tld. 1799 IN TXT "PY7ttk6no_5eG7WtAbO6qs5-NzA-Kigko375omKc0nw"
  128. Setup for multiple domains on Let's Encrypt
  129. ===========================================
  130. Before setting up multiple domains, make sure you have SSL working on your main domain using the instructions above.
  131. **Create shared nginx host file for all domains**
  132. ``vim /etc/nginx/includes/fusionpbx-default-config``
  133. Paste the code below into the file
  134. ::
  135. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  136. ssl_ciphers HIGH:!ADH:!MD5:!aNULL;
  137. #letsencrypt
  138. location /.well-known/acme-challenge {
  139. root /var/www/letsencrypt;
  140. }
  141. #REST api
  142. if ($uri ~* ^.*/api/.*$) {
  143. rewrite ^(.*)/api/(.*)$ $1/api/index.php?rewrite_uri=$2 last;
  144. break;
  145. }
  146. #algo
  147. rewrite "^.*/provision/algom([A-Fa-f0-9]{12})\.conf" /app/provision/?mac=$1&file=algom%7b%24mac%7d.conf last;
  148. #mitel
  149. rewrite "^.*/provision/MN_([A-Fa-f0-9]{12})\.cfg" /app/provision/index.php?mac=$1&file=MN_%7b%24mac%7d.cfg last;
  150. rewrite "^.*/provision/MN_Generic.cfg" /app/provision/index.php?mac=08000f000000&file=MN_Generic.cfg last;
  151. #grandstriam
  152. rewrite "^.*/provision/cfg([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/?mac=$1;
  153. #aastra
  154. rewrite "^.*/provision/aastra.cfg$" /app/provision/?mac=$1&file=aastra.cfg;
  155. #rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(cfg))?$" /app/provision/?mac=$1 last;
  156. #yealink common
  157. rewrite "^.*/provision/(y[0-9]{12})(\.cfg)?$" /app/provision/index.php?file=$1.cfg;
  158. #yealink mac
  159. rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/index.php?mac=$1 last;
  160. #polycom
  161. rewrite "^.*/provision/000000000000.cfg$" "/app/provision/?mac=$1&file={%24mac}.cfg";
  162. #rewrite "^.*/provision/sip_330(\.(ld))$" /includes/firmware/sip_330.$2;
  163. rewrite "^.*/provision/features.cfg$" /app/provision/?mac=$1&file=features.cfg;
  164. rewrite "^.*/provision/([A-Fa-f0-9]{12})-sip.cfg$" /app/provision/?mac=$1&file=sip.cfg;
  165. rewrite "^.*/provision/([A-Fa-f0-9]{12})-phone.cfg$" /app/provision/?mac=$1;
  166. rewrite "^.*/provision/([A-Fa-f0-9]{12})-registration.cfg$" "/app/provision/?mac=$1&file={%24mac}-registration.cfg";
  167. #cisco
  168. rewrite "^.*/provision/file/(.*\.(xml|cfg))" /app/provision/?file=$1 last;
  169. #Escene
  170. rewrite "^.*/provision/([0-9]{1,11})_Extern.xml$" "/app/provision/?ext=$1&file={%24mac}_extern.xml" last;
  171. rewrite "^.*/provision/([0-9]{1,11})_Phonebook.xml$" "/app/provision/?ext=$1&file={%24mac}_phonebook.xml" last;
  172. access_log /var/log/nginx/access.log;
  173. error_log /var/log/nginx/error.log;
  174. client_max_body_size 80M;
  175. client_body_buffer_size 128k;
  176. location / {
  177. root /var/www/fusionpbx;
  178. index index.php;
  179. }
  180. location ~ \.php$ {
  181. fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
  182. #fastcgi_pass 127.0.0.1:9000;
  183. fastcgi_index index.php;
  184. include fastcgi_params;
  185. fastcgi_param SCRIPT_FILENAME /var/www/fusionpbx$fastcgi_script_name;
  186. }
  187. # Disable viewing .htaccess & .htpassword & .db
  188. location ~ .htaccess {
  189. deny all;
  190. }
  191. location ~ .htpassword {
  192. deny all;
  193. }
  194. location ~^.+.(db)$ {
  195. deny all;
  196. }
  197. **Create a file to contain config for additional domains**
  198. ``touch /etc/nginx/includes/fusionpbx-domains``
  199. **make default file read configs for additional domains**
  200. ``vim /etc/nginx/sites-available/fusionpbx``
  201. Add the line below at the very end of the file after the trailing "}"
  202. ``include /etc/nginx/includes/fusionpbx-domains;``
  203. By now you are all set to start using SSL on multiple domains for your FusionPBX installation.
  204. **Follow the steps below every time you add a new domain**
  205. Create a conf file for the new domain (replace example.com with your own domain)
  206. ``vim /etc/letsencrypt/configs/example.com.conf``
  207. Paste this into the .conf file (don't forget to change the defaults, especially the domain)
  208. ::
  209. # the domain we want to get the cert for;
  210. # technically it's possible to have multiple of these lines, but it only worked
  211. # with one domain for me, another one only got one cert, so I would recommend
  212. # Separate config files per domain.
  213. domains = my-domain
  214. # increase key size
  215. rsa-key-size = 2048 # Or 4096
  216. # the current closed beta (as of 2015-Nov-07) is using this server
  217. server = https://acme-v01.api.letsencrypt.org/directory
  218. # this address will receive renewal reminders
  219. email = my-email
  220. # turn off the ncurses UI, we want this to be run as a cronjob
  221. text = True
  222. # authenticate by placing a file in the webroot (under .well-known/acme-upatechallenge/)
  223. # and then letting LE fetch it
  224. authenticator = webroot
  225. webroot-path = /var/www/letsencrypt/
  226. Obtain the cert from Let's Encrypt (again, replace example.com with your domain)
  227. ::
  228. cd /etc/dehydrated/certs
  229. /usr/local/sbin/dehydrated -c -f /etc/dehydrated/config
  230. **Set cert to auto-renew with other domains**
  231. ::
  232. cd /etc/fusionpbx
  233. vim renew-letsencrypt.sh
  234. Add the line below right below where it says "cd /opt/letsencrypt/" (again replace example.com with your domain)
  235. /usr/local/sbin/dehydrated -c -f /etc/dehydrated/config
  236. /usr/sbin/service nginx restart
  237. Finally, add your new domain to be loaded
  238. ``vim /etc/nginx/includes/fusionpbx-domains``
  239. Paste the below at the very end of the file (again replace example.com with your domain)
  240. ::
  241. server {
  242. listen 443 ssl;
  243. server_name example.com;
  244. ssl on;
  245. ssl_certificate /etc/dehydrated/certs/example.com/fullchain.pem;
  246. ssl_certificate_key /etc/dehydrated/certs/example.com/privkey.pem;
  247. include /etc/nginx/includes/fusionpbx-default-config;
  248. }
  249. You're all set! Restart nginx for changes to take effect
  250. ``service nginx restart``
  251. .. _link: https://www.nginx.com/blog/free-certificates-lets-encrypt-and-nginx
  252. .. _Verto Communicator: https://freeswitch.org/confluence/display/FREESWITCH/Verto+Communicator