Ngnix上配置HTTPS不算特别复杂,下面记录一下整体过程。
生成自签名的SSL证书
通过下面命令生成一系列文件,最终只需要server.key和server.crt两个就可以了
openssl genrsa -des3 -out server_temp.key 2048
openssl req -new -key server_temp.key -out server.csr -config openssl.cnf //如果需要配置的是基于IP地址的,就用下面的openssl.cnf,否则可以不需要这个配置参数
openssl req -text -in server.csr -noout
openssl rsa -in server_temp.key -out server.key
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
openssl.cnf内容:
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[req_distinguished_name]
C = 国家名
ST = 省份名
L = 城市名
O = 你的公司
OU = 你的部门
CN = 你的域名
[v3_req]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
IP.1 = 你的IP地址
Nginx配置
server {
listen 443 ssl;
server_name nginx; // 这个可以改
ssl_certificate /etc/ssl/certs/server.crt; // 证书位置
ssl_certificate_key /etc/ssl/certs/server.key; // 私钥位置
location / {
proxy_pass http://frontend:port/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ^~/backend/ {
proxy_pass http://backend:port/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
标签:配置,http,key,req,openssl,server,Nginx,proxy,HTTPS
From: https://www.cnblogs.com/alexanderzjs/p/17498733.html