以下操作在centos 下執(zhí)行:
cd/opt/ssl 證書制作路徑
1)openssl genrsa -des3 -out domain.key 1024
生成RSA密鑰(過程需要設(shè)置一個(gè)密碼,記住這個(gè)密碼)
2)openssl rsa -in domain.key -out domain_nopass.key
拷貝一個(gè)不需要輸入密碼的密鑰文件
3)openssl req -new -key domain.key -out domain.csr
這里會(huì)提示輸入國家,地區(qū)組織,email等信息.最重要的一個(gè)是”common name”,需要與網(wǎng)站域名相同.
[root@localhost ssl]# openssl req -new -key domain.key -out domain.csr
Enter pass phrase for domain.key: ####1) 密碼
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a CN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [XX]:cn 國家
State or Province Name (full name) []:zj 省
Locality Name (eg, city) [Default City]:hz 城市
Organization Name (eg, company) [Default Company Ltd]:tset 機(jī)構(gòu)名稱
Organizational Unit Name (eg, section) []:test 單位名稱
Common Name (eg, your name or your server’s hostname) []:domain.com 網(wǎng)站域名
Email Address []: 郵箱 可以回車
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: 可以回車
An optional company name []: 可以回車
輸入完這些就會(huì)生成一個(gè)domain.csr文件,提交給ssl提供商的時(shí)候就是這個(gè)csr文件.當(dāng)然這里并沒有向任何證書提供商申請(qǐng),而是自己簽發(fā)證書.
使用上面的密鑰和CSR對(duì)證書簽名$ openssl x509 -req -days 365 -in domain.csr -signkey domain.key -out domain.crt
備注:這個(gè)365 時(shí)間可以多寫點(diǎn)。
檢測nginx是否支持SSL:$ nginx -V如果有顯示-with-http_ssl_module表示已編譯openssl,支持安裝ssl.如果沒有,請(qǐng)重新編譯安裝nginx
參考配置文件
server {
listen 80;
listen [::]:80;
server_name x.x.x.x; #可以寫成服務(wù)器地址
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /status {
stub_status on;
access_log off;
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://domain.com; ###反向代理地址
rewrite ^(.*)$ https://$host$1 permanent;
}
}
# Settings for a TLS enabled server.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name 10.100.124.6;
ssl_certificate “/opt/ssl/domain.pem”; ## 證書地址
ssl_certificate_key “/opt/ssl/domain_nopass.key”; ### 證書地址
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://domain.com; ## 反向代理地址,如無反向代理地址可以家#注解
}
}
}