国产精品主播叶子闺蜜_三级高清精品国产_99久久精品国产麻豆_国产精品无码免费专区午夜

歡迎您光臨深圳塔燈網絡科技有限公司!
電話圖標 余先生:13699882642

網站百科

為您解碼網站建設的點點滴滴

Ngnix.SSL

發表日期:2017-04 文章編輯:小燈 瀏覽次數:2904

使用ssl模塊配置同時支持http和https并存
一,生成證書

1、首先,進入你想創建證書和私鑰的目錄,例如:cd /etc/nginx/# 2、創建服務器私鑰,命令會讓你輸入一個口令:openssl genrsa -des3 -out server.key 1024# 3、創建簽名請求的證書(CSR):openssl req -new -key server.key -out server.csr# 4、在加載SSL支持的Nginx并使用上述私鑰時除去必須的口令:cp server.key server.key.orgopenssl rsa -in server.key.org -out server.key# 5、最后標記證書使用上述私鑰和CSR:openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

二,配置nginx
cd /etc/nginxvim nginx.conf## HTTPS server configuration#server { listen 443; server_name 本機的IP地址; ssl on; ssl_certificate /etc/nginx/server.crt; ssl_certificate_key /etc/nginx/server.key; ssl_session_timeout 5m;# ssl_protocols SSLv2 SSLv3 TLSv1;# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;# ssl_prefer_server_ciphers on; location / { #root html; #index testssl.html index.html index.htm; 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 http://IP地址/ssl/; }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

重啟nginx,在瀏覽器輸入:https://IP地址 會跳轉到 http://IP地址/ssl/ 這個地址(后期調整為webservice接口地址即可)
三、受瀏覽器信任的StartSSL免費SSL證書:
跟VeriSign一樣,StartSSL(網址:http://www.startssl.com,公司名:StartCom)也是一家CA機構,
它的根證書很 久之前就被一些具有開源背景的瀏覽器支持(Firefox瀏覽器、谷歌Chrome瀏覽器、蘋果Safari瀏覽器等)。
四、項目需要,將訪問目錄 \services\ 由http訪問 重定向到 https (解決方法:nginx rewrite 加上 location 方式實現)
location ~ /services/.$ { if ($server_port ~ "^80$"){ set $rule_0 1$rule_0; } if ($rule_0 = "1"){ rewrite /(.) https://IP地址/$1 permanent; break; } }
1
2
3
4
5
6
7
8

1
2
3
4
5
6
7
8

五,配置結束上傳以后用nginx -t 測試下配置無誤 就reload一下nginx服務 檢查443端口是否在監聽
/usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful (顯示表示配置文件沒有錯誤)service nginx reload (重新加載nginx服務) netstat -lan | grep 443 (查看443端口) tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN (有看到這一行 就表示HTTPS已經在工作了)


本頁內容由塔燈網絡科技有限公司通過網絡收集編輯所得,所有資料僅供用戶學習參考,本站不擁有所有權,如您認為本網頁中由涉嫌抄襲的內容,請及時與我們聯系,并提供相關證據,工作人員會在5工作日內聯系您,一經查實,本站立刻刪除侵權內容。本文鏈接:http://www.juherenli.com/20386.html
相關開發語言