一、证书和私钥的生成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
1 .创建服务器证书密钥文件 server.key:
openssl genrsa -des3 -out server.key 2048
输入密码,确认密码,自己随便定义,但是要记住,后面会用到。
2 .创建服务器证书的申请文件 server.csr
openssl req - new -key server.key -out server.csr
输出内容为:
Enter pass phrase for root.key: ← 输入前面创建的密码
Country Name ( 2 letter code) [AU]:CN ← 国家代号,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音
Locality Name (eg, city) []:BeiJing ← 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []: ← 输入域名,如:iot.conet.com
Email Address []:admin @mycompany .com ← 电子邮箱,可随意填
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入
4 .备份一份服务器密钥文件
cp server.key server.key.org
5 .去除文件口令
openssl rsa -in server.key.org -out server.key
6 .生成证书文件server.crt
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
|
二、配置证书
server { listen 443 ssl; listen 80; #内网端口 server_name portal1; ssl_certificate conf.d/key/server.crt; ssl_certificate_key conf.d/key/server.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; large_client_header_buffers 4 16k; client_body_buffer_size 128k; proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600; proxy_buffer_size 64k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_set_header Host $host:$server_port; #保留代理之前的host proxy_set_header X-Real-IP $remote_addr; #保留代理之前的真实客户端ip proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr; #在多级代理的情况下,记录每次代理之前的客户端真实ip client_max_body_size 10m; #上传文件大小限制 add_header X-Frame-Options SAMEORIGIN; #X-Frame-Options 低危漏洞 proxy_intercept_errors on; recursive_error_pages on; server_tokens off; #错误页面隐藏版本号
标签:https,ssl,证书,header,server,Nginx,proxy,key,Name From: https://www.cnblogs.com/exmyth/p/17031239.html