参考 https://blog.csdn.net/weixin_34296646/article/details/112642008
工具地址 : https://github.com/square/certstrap
chmod 777 certstrap
# 要进行证书自签名,首先是生成一个自信任的CA认证证书。
./certstrap init --common-name "ca" --expires "20 years"
### 服务端证书
# 首先创建CSR, 即证书签名请求
./certstrap request-cert -cn server -ip xxx.xxx.xxx.xxx
# 生成CSR之后,通过刚刚生成的CA证书进行签名.
./certstrap sign server --CA ca
这样就完成了服务端证书的签名,签名后的证书就是:out/server.crt
### 客户端证书
./certstrap request-cert -cn client
./certstrap sign client --CA ca
(crt 改成pem即可)
upstream imserver {
server 0.0.0.0:8088;
keepalive 32;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
# 证书参数
listen 443 ssl;
# 证书参数
ssl_certificate /etc/nginx/conf.d/ssl/server.crt;
ssl_certificate_key /etc/nginx/conf.d/ssl/server.key;
# 证书参数
ssl on;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 300;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
server_name im;
access_log logs/im.log;
error_log logs/im.error;
location =/ {
auth_basic "valid user";
auth_basic_user_file /etc/nginx/htpasswd.users;
proxy_pass http://imserver;
}
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 50M;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_buffers 256 16k;
proxy_buffer_size 16k;
proxy_read_timeout 600s;
proxy_pass http://imserver;
}
location ~ /api/v4/trial-license/prev {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 50M;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_buffers 256 16k;
proxy_buffer_size 16k;
proxy_read_timeout 600s;
proxy_pass http://imserver;
}
location / {
proxy_pass http://imserver;
}
}