lets_encrypt.rst 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. Let's Encrypt
  2. ==============
  3. Let's Encrypt is one of the most recent and widely used form of free SSL security but doesn't support wildcard DNS. You can use Let's Encrypt with your FusionPBX install and WebRTC like `Verto Communicator`_.
  4. More info on NGINX with Let's Encrypt
  5. https://www.nginx.com/blog/free-certificates-lets-encrypt-and-nginx
  6. **Clone Let's Encrypt**
  7. ::
  8. git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
  9. **Execute certbot-auto**
  10. ::
  11. cd /opt/letsencrypt
  12. chmod a+x ./certbot-auto
  13. ./certbot-auto
  14. cd /etc/letsencrypt/
  15. mkdir -p configs
  16. cd configs
  17. **Copy code example from** `link`_ **in step #2 section and edit domains, key size, email then put into: /etc/letsencrypt/configs/domain.tld.conf** (Edit domain.tld to reflect your domain)
  18. ::
  19. touch /etc/letsencrypt/configs/domain.tld.conf
  20. vim /etc/letsencrypt/configs/domain.tld.conf
  21. **Edit /etc/nginx/sites-available/fusionpbx**
  22. ::
  23. vim /etc/nginx/sites-available/fusionpbx
  24. Add this after the ssl_ciphers line
  25. location /.well-known/acme-challenge {
  26. root /var/www/letsencrypt;
  27. }
  28. Reload and check Nginx
  29. nginx -t && nginx -s reload
  30. Should output:
  31. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  32. nginx: configuration file /etc/nginx/nginx.conf test is successful
  33. **Execute Let's Encrypt script** (Edit domain.tld to reflect your domain)
  34. You can make up to 100 subdomain requests with using -d sub.domain.tld -d sub1.domain.tld
  35. ::
  36. cd /opt/letsencrypt
  37. ./letsencrypt-auto --config /etc/letsencrypt/configs/domain.tld.conf certonly
  38. Should output:
  39. - Congratulations! And a paragraph about the keys made and where the live.
  40. **Edit sites-available** (Edit domain.tld to reflect your domain)
  41. ::
  42. Comment out and add
  43. vim /etc/nginx/sites-available/fusionpbx
  44. #ssl_certificate /etc/ssl/certs/nginx.crt;
  45. #ssl_certificate_key /etc/ssl/private/nginx.key;
  46. ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
  47. ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
  48. Systemctl restart nginx
  49. **Auto Renew certificate**
  50. ::
  51. cd /etc/fusionpbx/
  52. touch renew-letsencrypt.sh
  53. Put code example from Automating Renewal section step#1 into renew-letsencrypt.sh
  54. Edit the my-domain.conf with the domain name you used a few steps earlier
  55. Create crontab -e
  56. 0 0 1 JAN,MAR,MAY,JUL,SEP,NOV * /path/to/renew-letsencrypt.sh
  57. This executes every two months
  58. chmod +x renew-letsencrypt.sh
  59. Now check the padlock and see if it's green!
  60. Setup for multiple domains on Let's Encrypt
  61. ===========================================
  62. Before setting up multiple domains, make sure you have SSL working on your main domain using the instructions above.
  63. **Create shared nginx host file for all domains**
  64. ``vim /etc/nginx/includes/fusionpbx-default-config``
  65. Paste the code below into the file
  66. ::
  67. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  68. ssl_ciphers HIGH:!ADH:!MD5:!aNULL;
  69. #letsencrypt
  70. location /.well-known/acme-challenge {
  71. root /var/www/letsencrypt;
  72. }
  73. #REST api
  74. if ($uri ~* ^.*/api/.*$) {
  75. rewrite ^(.*)/api/(.*)$ $1/api/index.php?rewrite_uri=$2 last;
  76. break;
  77. }
  78. #algo
  79. rewrite "^.*/provision/algom([A-Fa-f0-9]{12})\.conf" /app/provision/?mac=$1&file=algom%7b%24mac%7d.conf last;
  80. #mitel
  81. rewrite "^.*/provision/MN_([A-Fa-f0-9]{12})\.cfg" /app/provision/index.php?mac=$1&file=MN_%7b%24mac%7d.cfg last;
  82. rewrite "^.*/provision/MN_Generic.cfg" /app/provision/index.php?mac=08000f000000&file=MN_Generic.cfg last;
  83. #grandstriam
  84. rewrite "^.*/provision/cfg([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/?mac=$1;
  85. #aastra
  86. rewrite "^.*/provision/aastra.cfg$" /app/provision/?mac=$1&file=aastra.cfg;
  87. #rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(cfg))?$" /app/provision/?mac=$1 last;
  88. #yealink common
  89. rewrite "^.*/provision/(y[0-9]{12})(\.cfg)?$" /app/provision/index.php?file=$1.cfg;
  90. #yealink mac
  91. rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/index.php?mac=$1 last;
  92. #polycom
  93. rewrite "^.*/provision/000000000000.cfg$" "/app/provision/?mac=$1&file={%24mac}.cfg";
  94. #rewrite "^.*/provision/sip_330(\.(ld))$" /includes/firmware/sip_330.$2;
  95. rewrite "^.*/provision/features.cfg$" /app/provision/?mac=$1&file=features.cfg;
  96. rewrite "^.*/provision/([A-Fa-f0-9]{12})-sip.cfg$" /app/provision/?mac=$1&file=sip.cfg;
  97. rewrite "^.*/provision/([A-Fa-f0-9]{12})-phone.cfg$" /app/provision/?mac=$1;
  98. rewrite "^.*/provision/([A-Fa-f0-9]{12})-registration.cfg$" "/app/provision/?mac=$1&file={%24mac}-registration.cfg";
  99. #cisco
  100. rewrite "^.*/provision/file/(.*\.(xml|cfg))" /app/provision/?file=$1 last;
  101. #Escene
  102. rewrite "^.*/provision/([0-9]{1,11})_Extern.xml$" "/app/provision/?ext=$1&file={%24mac}_extern.xml" last;
  103. rewrite "^.*/provision/([0-9]{1,11})_Phonebook.xml$" "/app/provision/?ext=$1&file={%24mac}_phonebook.xml" last;
  104. access_log /var/log/nginx/access.log;
  105. error_log /var/log/nginx/error.log;
  106. client_max_body_size 80M;
  107. client_body_buffer_size 128k;
  108. location / {
  109. root /var/www/fusionpbx;
  110. index index.php;
  111. }
  112. location ~ \.php$ {
  113. fastcgi_pass unix:/var/run/php5-fpm.sock;
  114. #fastcgi_pass 127.0.0.1:9000;
  115. fastcgi_index index.php;
  116. include fastcgi_params;
  117. fastcgi_param SCRIPT_FILENAME /var/www/fusionpbx$fastcgi_script_name;
  118. }
  119. # Disable viewing .htaccess & .htpassword & .db
  120. location ~ .htaccess {
  121. deny all;
  122. }
  123. location ~ .htpassword {
  124. deny all;
  125. }
  126. location ~^.+.(db)$ {
  127. deny all;
  128. }
  129. **Create a file to contain config for additional domains**
  130. ``touch /etc/nginx/includes/fusionpbx-domains``
  131. **make default file read configs for additional domains**
  132. ``vim /etc/nginx/sites-available/fusionpbx``
  133. Add the line below at the very end of the file after the trailing "}"
  134. ``include /etc/nginx/includes/fusionpbx-domains;``
  135. By now you are all set to start using SSL on multiple domains for your FusionPBX installation.
  136. **Follow the steps below everytime your add a new domain**
  137. Create a conf file for the new domain (repalce example.com with your own domain)
  138. ``vim /etc/letsencrypt/configs/example.com.conf``
  139. Paste this into the .conf file (don't forget to change the defaults, especially the domain)
  140. ::
  141. # the domain we want to get the cert for;
  142. # technically it's possible to have multiple of this lines, but it only worked
  143. # with one domain for me, another one only got one cert, so I would recommend
  144. # separate config files per domain.
  145. domains = my-domain
  146. # increase key size
  147. rsa-key-size = 2048 # Or 4096
  148. # the current closed beta (as of 2015-Nov-07) is using this server
  149. server = https://acme-v01.api.letsencrypt.org/directory
  150. # this address will receive renewal reminders
  151. email = my-email
  152. # turn off the ncurses UI, we want this to be run as a cronjob
  153. text = True
  154. # authenticate by placing a file in the webroot (under .well-known/acme-upatechallenge/)
  155. # and then letting LE fetch it
  156. authenticator = webroot
  157. webroot-path = /var/www/letsencrypt/
  158. Obtain the cert from Let's Encrypt (again, replce example.com with your domain)
  159. ::
  160. cd /opt/letsencrypt
  161. ./letsencrypt-auto --config /etc/letsencrypt/configs/example.com.conf certonly
  162. **Set cert to auto renew with other domains**
  163. ::
  164. cd /etc/fusionpbx
  165. vim renew-letsencrypt.sh
  166. Add the line below right below where it says "cd /opt/letsencrypt/" (again replace example.com with your domain)
  167. ``./certbot-auto --config /etc/letsencrypt/configs/example.com.conf certonly --non-interactive --keep-until-expiring --agree-tos --quiet``
  168. Finally add your new domain to be loaded
  169. ``vim /etc/nginx/includes/fusionpbx-domains``
  170. Paste the below at the very end of the file (again replace example.com with your domain)
  171. ::
  172. server {
  173. listen 443;
  174. server_name example.com;
  175. ssl on;
  176. ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  177. ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  178. include /etc/nginx/includes/fusionpbx-default-config;
  179. }
  180. You're all set! Restart nginx for changes to take effect
  181. ``service nginx restart``
  182. .. _link: https://www.nginx.com/blog/free-certificates-lets-encrypt-and-nginx
  183. .. _Verto Communicator: https://freeswitch.org/confluence/display/FREESWITCH/Verto+Communicator