SSL部署

1.申请https证书

  1. certbot certonly --manual -d *.liuwenwen.net --agree-tos --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
  1. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2. Please deploy a DNS TXT record under the name:
  3. _acme-challenge.liuwenwen.net.
  4. with the following value:
  5. d5RIrmT_mwj-Kp1qYYY1klzcCzqwcKBjYCnkM4B2BHc
  6. Before continuing, verify the TXT record has been deployed. Depending on the DNS
  7. provider, this may take some time, from a few seconds to multiple minutes. You can
  8. check if it has finished deploying with aid of online tools, such as the Google
  9. Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.liuwenwen.net.
  10. Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
  11. value(s) you've just added.
  12. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  13. Press Enter to Continue
  14. Successfully received certificate.
  15. Certificate is saved at: /etc/letsencrypt/live/liuwenwen.net/fullchain.pem
  16. Key is saved at: /etc/letsencrypt/live/liuwenwen.net/privkey.pem
  17. This certificate expires on 2021-12-09.
  18. These files will be updated when the certificate renews.
  19. NEXT STEPS:
  20. - This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.
  21. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  22. If you like Certbot, please consider supporting our work by:
  23. * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
  24. * Donating to EFF: https://eff.org/donate-le
  25. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

2.重命名https证书

  1. root@hongkong:/etc/pki/nginx# ls -l
  2. total 12
  3. -rw-r--r-- 1 root root 5592 Sep 10 21:50 fullchain.crt
  4. -rw-r--r-- 1 root root 1705 Sep 10 21:51 privkey.key

3.配置站点信息

  1. ##
  2. # You should look at the following URL's in order to grasp a solid understanding
  3. # of Nginx configuration files in order to fully unleash the power of Nginx.
  4. # https://www.nginx.com/resources/wiki/start/
  5. # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
  6. # https://wiki.debian.org/Nginx/DirectoryStructure
  7. #
  8. # In most cases, administrators will remove this file from sites-enabled/ and
  9. # leave it as reference inside of sites-available where it will continue to be
  10. # updated by the nginx packaging team.
  11. #
  12. # This file will automatically load configuration files provided by other
  13. # applications, such as Drupal or Wordpress. These applications will be made
  14. # available underneath a path with that package name, such as /drupal8.
  15. #
  16. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  17. ##
  18. # Default server configuration
  19. #
  20. server {
  21. listen 80 default_server;
  22. listen [::]:80 default_server;
  23. # SSL configuration
  24. #
  25. # listen 443 ssl default_server;
  26. # listen [::]:443 ssl default_server;
  27. #
  28. # Note: You should disable gzip for SSL traffic.
  29. # See: https://bugs.debian.org/773332
  30. #
  31. # Read up on ssl_ciphers to ensure a secure configuration.
  32. # See: https://bugs.debian.org/765782
  33. #
  34. # Self signed certs generated by the ssl-cert package
  35. # Don't use them in a production server!
  36. #
  37. # include snippets/snakeoil.conf;
  38. root /var/www/html;
  39. # Add index.php to the list if you are using PHP
  40. index index.html index.htm index.nginx-debian.html;
  41. server_name _;
  42. rewrite ^(.*)$ https://$host$1 permanent;
  43. # location / {
  44. # First attempt to serve request as file, then
  45. # as directory, then fall back to displaying a 404.
  46. # try_files $uri $uri/ =404;
  47. # }
  48. # pass PHP scripts to FastCGI server
  49. #
  50. #location ~ \.php$ {
  51. # include snippets/fastcgi-php.conf;
  52. #
  53. # # With php-fpm (or other unix sockets):
  54. # fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  55. # # With php-cgi (or other tcp sockets):
  56. # fastcgi_pass 127.0.0.1:9000;
  57. #}
  58. # deny access to .htaccess files, if Apache's document root
  59. # concurs with nginx's one
  60. #
  61. #location ~ /\.ht {
  62. # deny all;
  63. #}
  64. }
  65. server {
  66. # listen 80 default_server;
  67. # listen [::]:80 default_server;
  68. # SSL configuration
  69. #
  70. listen 443 ssl default_server;
  71. listen [::]:443 ssl default_server;
  72. ssl_certificate /etc/pki/nginx/fullchain.crt;
  73. ssl_certificate_key /etc/pki/nginx/privkey.key;
  74. #
  75. # Note: You should disable gzip for SSL traffic.
  76. # See: https://bugs.debian.org/773332
  77. #
  78. # Read up on ssl_ciphers to ensure a secure configuration.
  79. # See: https://bugs.debian.org/765782
  80. #
  81. # Self signed certs generated by the ssl-cert package
  82. # Don't use them in a production server!
  83. #
  84. # include snippets/snakeoil.conf;
  85. root /var/www/html;
  86. # Add index.php to the list if you are using PHP
  87. index index.html index.htm index.nginx-debian.html;
  88. server_name _;
  89. location / {
  90. # First attempt to serve request as file, then
  91. # as directory, then fall back to displaying a 404.
  92. try_files $uri $uri/ =404;
  93. }
  94. # pass PHP scripts to FastCGI server
  95. #
  96. #location ~ \.php$ {
  97. # include snippets/fastcgi-php.conf;
  98. #
  99. # # With php-fpm (or other unix sockets):
  100. # fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  101. # # With php-cgi (or other tcp sockets):
  102. # fastcgi_pass 127.0.0.1:9000;
  103. #}
  104. # deny access to .htaccess files, if Apache's document root
  105. # concurs with nginx's one
  106. #
  107. #location ~ /\.ht {
  108. # deny all;
  109. #}
  110. }
  111. # Virtual Host configuration for example.com
  112. #
  113. # You can move that to a different file under sites-available/ and symlink that
  114. # to sites-enabled/ to enable it.
  115. #
  116. #server {
  117. # listen 80;
  118. # listen [::]:80;
  119. #
  120. # server_name example.com;
  121. #
  122. # root /var/www/example.com;
  123. # index index.html;
  124. #
  125. # location / {
  126. # try_files $uri $uri/ =404;
  127. # }
  128. #}