• 给nginx部署https及自签名ssl证书


     一、生成服务器root证书

    1. openssl genrsa -out root.key 2048
    2. openssl req -new -key root.key -out root.csr
    3. #Country Name (2 letter code) [XX]:---> CN
    4. #Country Name (2 letter code) [XX]:---> CN
    5. #State or Province Name (full name) []:---> Shanghai
    6. #Locality Name (eg, city) [Default City]:---> Shanghai
    7. #Organization Name (eg, company) [Default Company Ltd]:---> kahn commpany
    8. #Organizational Unit Name (eg, section) []:---> xou
    9. #Common Name (eg, your name or your server's hostname) []:---> kahn.com
    10. #Email Address []:---> 37213690@qq.com
    11. #A challenge password []:---> 回车
    12. #An optional company name []:---> 回车
    13. openssl x509 -req -days 3650 -in root.csr -signkey root.key -out root.crt

    二、生成SSL服务器证书

    1. openssl genrsa -out server.key 2048
    2. openssl req -new -key server.key -out server.csr
    3. #Country Name (2 letter code) [XX]:---> CN
    4. #State or Province Name (full name) []:---> Shanghai
    5. #Locality Name (eg, city) [Default City]:---> Shanghai
    6. #Organization Name (eg, company) [Default Company Ltd]:---> kahn commpany
    7. #Organizational Unit Name (eg, section) []:---> xou
    8. #Common Name (eg, your name or your server's hostname) []:---> kahn.com
    9. #Email Address []:---> 37213690@qq.com
    10. #A challenge password []:---> 回车
    11. #An optional company name []:---> 回车
    12. openssl x509 -req -in server.csr -CA root.crt -CAkey root.key -CAcreateserial -out server.crt -days 3650

    #会生成如下6个文件,其中server.*用于nginx
    root.crt  root.csr  root.key  root.srl  server.crt  server.csr  server.key

    三、部署证书到nginx

    下面是一个测试通过的nginx.conf内容

    1. user nginx nginx;
    2. worker_processes 1;
    3. #error_log logs/error.log;
    4. #error_log logs/error.log notice;
    5. #error_log logs/error.log info;
    6. #pid logs/nginx.pid;
    7. events {
    8. worker_connections 1024;
    9. }
    10. http {
    11. include mime.types;
    12. default_type application/octet-stream;
    13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    14. # '$status $body_bytes_sent "$http_referer" '
    15. # '"$http_user_agent" "$http_x_forwarded_for"';
    16. #access_log logs/access.log main;
    17. sendfile on;
    18. #tcp_nopush on;
    19. #keepalive_timeout 0;
    20. keepalive_timeout 65;
    21. #gzip on;
    22. server {
    23. listen 80;
    24. server_name localhost;
    25. #charset koi8-r;
    26. #access_log logs/host.access.log main;
    27. location / {
    28. root html;
    29. index index.html index.htm;
    30. }
    31. #error_page 404 /404.html;
    32. # redirect server error pages to the static page /50x.html
    33. #
    34. error_page 500 502 503 504 /50x.html;
    35. location = /50x.html {
    36. root html;
    37. }
    38. }
    39. # HTTPS server
    40. server {
    41. listen 443 ssl;
    42. server_name kahn.com;
    43. ssl_certificate ../ssl-certs/server.crt;
    44. ssl_certificate_key ../ssl-certs/server.key;
    45. ssl_session_cache shared:SSL:1m;
    46. ssl_session_timeout 5m;
    47. ssl_ciphers HIGH:!aNULL:!MD5;
    48. ssl_prefer_server_ciphers on;
    49. location / {
    50. alias /data/www/;
    51. index index.html index.htm;
    52. }
    53. }
    54. include ../conf.d/*.conf;
    55. }

    主要看    # HTTPS server
        server {
            listen       443 ssl;
            server_name  x179.com;及以下内容。

    值的注意的是,开启https是在http{}区域内部,并且和其他server{}同级。

    四、验证ssl证书

    openssl s_client -connect kahn.com:443

  • 相关阅读:
    从TF-IDF 到BM25, BM25+,一文彻底理解文本相关度
    线程池底层原理详解与源码分析(补充部分---ScheduledThreadPoolExecutor类分析)
    Spring Boot、Nacos配置文件的优先级
    C:strcpy和strncpy的陷阱
    内江科技杂志内江科技杂志社内江科技编辑部2024年第13期目录
    【Flink实战】Flink对接Kafka Connetor使用docker部署kafka
    Unity实现简易太阳系
    常识——虚拟机安装centos7与联网
    win10专业版驱动开发
    【Docker】用Dockerfile制作个人的镜像文件
  • 原文地址:https://blog.csdn.net/xoofly/article/details/136368960