参考 https://blog.csdn.net/weixin_34296646/article/details/112642008

    工具地址 : https://github.com/square/certstrap

    1. chmod 777 certstrap
    2. # 要进行证书自签名,首先是生成一个自信任的CA认证证书。
    3. ./certstrap init --common-name "ca" --expires "20 years"
    4. ### 服务端证书
    5. # 首先创建CSR, 即证书签名请求
    6. ./certstrap request-cert -cn server -ip xxx.xxx.xxx.xxx
    7. # 生成CSR之后,通过刚刚生成的CA证书进行签名.
    8. ./certstrap sign server --CA ca
    9. 这样就完成了服务端证书的签名,签名后的证书就是:out/server.crt
    10. ### 客户端证书
    11. ./certstrap request-cert -cn client
    12. ./certstrap sign client --CA ca

    image.png
    (crt 改成pem即可)

    1. upstream imserver {
    2. server 0.0.0.0:8088;
    3. keepalive 32;
    4. }
    5. map $http_upgrade $connection_upgrade {
    6. default upgrade;
    7. '' close;
    8. }
    9. server {
    10. listen 80;
    11. # 证书参数
    12. listen 443 ssl;
    13. # 证书参数
    14. ssl_certificate /etc/nginx/conf.d/ssl/server.crt;
    15. ssl_certificate_key /etc/nginx/conf.d/ssl/server.key;
    16. # 证书参数
    17. ssl on;
    18. ssl_session_cache shared:SSL:50m;
    19. ssl_session_timeout 300;
    20. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    21. ssl_ciphers HIGH:!aNULL:!MD5;
    22. ssl_prefer_server_ciphers on;
    23. server_name im;
    24. access_log logs/im.log;
    25. error_log logs/im.error;
    26. location =/ {
    27. auth_basic "valid user";
    28. auth_basic_user_file /etc/nginx/htpasswd.users;
    29. proxy_pass http://imserver;
    30. }
    31. location ~ /api/v[0-9]+/(users/)?websocket$ {
    32. proxy_set_header Upgrade $http_upgrade;
    33. proxy_set_header Connection "upgrade";
    34. client_max_body_size 50M;
    35. proxy_set_header Host $http_host;
    36. proxy_set_header X-Real-IP $remote_addr;
    37. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    38. proxy_set_header X-Forwarded-Proto $scheme;
    39. proxy_set_header X-Frame-Options SAMEORIGIN;
    40. proxy_buffers 256 16k;
    41. proxy_buffer_size 16k;
    42. proxy_read_timeout 600s;
    43. proxy_pass http://imserver;
    44. }
    45. location ~ /api/v4/trial-license/prev {
    46. proxy_set_header Upgrade $http_upgrade;
    47. proxy_set_header Connection "upgrade";
    48. client_max_body_size 50M;
    49. proxy_set_header Host $http_host;
    50. proxy_set_header X-Real-IP $remote_addr;
    51. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    52. proxy_set_header X-Forwarded-Proto $scheme;
    53. proxy_set_header X-Frame-Options SAMEORIGIN;
    54. proxy_buffers 256 16k;
    55. proxy_buffer_size 16k;
    56. proxy_read_timeout 600s;
    57. proxy_pass http://imserver;
    58. }
    59. location / {
    60. proxy_pass http://imserver;
    61. }
    62. }