配置前提nginx裝了SSL功能模組。
[root@www conf]# openssl genrsa -out cert.key2 2048 產生cert.key2私密金鑰檔案
Generating RSA private key, 2048 bit long modulus
......................+++
..................................................................................+++
e is 65537 (0x10001)
[root@www conf]# openssl req -new -x509 -key cert.key2 -out cert.pem2 用cert.key2 產生 cert.pem2認證檔案
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 DN.
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) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []: 慢點。。。。下面要輸入東西了。
Common Name (eg, your name or your server's hostname) []:www.wang.com #輸你的網域名稱
Email Address []:
vim /usr/local/nginx/conf/nginx.conf 編輯設定檔 添加一個 server 可以複製我的在修修改改。
server {
listen 443; 連接埠號碼要改。
server_name www.wang.com; 網域名稱要改。
ssl on;
ssl_certificate /usr/local/nginx/conf/cert.pem2; 認證檔案 路徑寫好。
ssl_certificate_key /usr/local/nginx/conf/cert.key2; 私密金鑰檔案 路徑寫好。
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /var/www/html/web1; 你的網站目錄,最好寫絕對路徑。
index index.html index.htm; 首頁檔案。
}
}
防火牆添加一條允許443連接埠的命令。
弄好了 把nginx重啟 重載有時候不行,弄好了用
netstat-anput |grep nginx
看一下 nginx是不是監聽的443連接埠。
防火牆,核心防火牆 關。
訪問。
ok。