如何在雲幫上配置https

序 相關組件介紹

本次分享主要涉及到兩個模塊console模塊和openresty模塊。html

  • console模塊

即雲幫(ACP)控制檯模塊,爲用戶提供可視化Web操做界面,監聽443端口便可,對證書需求:域名證書便可。node

  • openresty模塊

即雲幫負載均衡模塊。雲幫全部的對外服務都配置在負載均衡上,都是經過負載均衡轉發到對應的應用與服務。大部分狀況下監聽443端口便可,若是單節點監聽非佔用端口便可。對證書需求:由於涉及的域名較多,這裏咱們選擇泛域名證書。nginx

大概的操做流程以下:docker

那麼接下來就說說如何具體去配置https。瀏覽器

0x00 利用openssl自簽證書

準備工做:服務器

cd /etc/goodrain/nginx/ssl #用於存放證書
mkdir console.goodrain.me #域名對應的目錄
cd console.goodrain.me

生成證書操做:負載均衡

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/goodrain/nginx/ssl/console.goodrain.me/console.key -out /etc/goodrain/nginx/ssl/console.goodrain.me/console.crt

特別說明:回車以後會讓填寫一些信息,這些適當根據提示填寫。可是最重要的就是要求Common Name填寫慎重,您須要輸入與您的服務器關聯的域名或您的服務器的公共IP地址。dom

demo以下:curl

Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:Goodrain, Inc.
Organizational Unit Name (eg, section) []:Cloud 
Common Name (eg, your name or your server's hostname) []:console.goodrain.me
Email Address []:info@goodrain.me

域名必定要寫本身所需https的域名。測試

0x01 雲幫控制檯支持https

  • 備份console配置文件

cp console ~/ #備份路徑自選,但不要備份到當前目錄下

  • 編輯console文件
#在原有的配置下添加以下配置
#ip同原配置裏的監聽8688的ip相同
server {
    listen ip:443;
    server_name console.goodrain.me;
        ssl          on;
    ssl_certificate /etc/nginx/ssl/console.goodrain.me/console.crt;
    ssl_certificate_key /etc/nginx/ssl/console.goodrain.me/console.key;
    location / {
        proxy_pass http://console;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout 60;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
    }
}

這樣配置的話,http和https都是支持的。若是想強制跳轉修改監控8688的server

server {
    listen ip:8688;
    server_name console.goodrain.me;
        rewrite ^(.*)$  https://$server_name$1 permanent;
}

修改完。重啓nginx服務。

dc-compose stop nginx
cclear
dc-compose up -d

配置到這裏,控制檯的https配置已經完成。 測試:

[root@iZm5e7u02k402beob2081gZ ~]# curl -I console.goodrain.me/login
HTTP/1.1 301 Moved Permanently
Server: openresty
Date: Thu, 30 Mar 2017 03:46:37 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: https://console.goodrain.me/login

若是是瀏覽器訪問,因爲證書是自籤的,須要添加信任。

0x02 平臺應用支持https

泛域名證書配置:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt

證書上傳到openresty服務裏:

docker cp server.crt openresty:/usr/local/openresty/nginx/conf/
docker cp server.key openresty:/usr/local/openresty/nginx/conf/

配置計算節點的openresty:

cd /etc/goodrain/openresty/servers/http
cp default.conf default443.conf
# 編輯default443.conf
修改以下:
listen       7443;
ssl on;
ssl_certificate /usr/local/openresty/nginx/conf/server.crt;
ssl_certificate_key /usr/local/openresty/nginx/conf/server.key;
 #其餘保持不變。

這裏監聽的是7443,由於個人是單節點部署的,443端口已經被其餘服務監聽,故使用7443端口。 配置完以上的,重啓openresty便可。

dc-compose stop openresty
cclear
dc-compose up -d

配置到這裏,應用的https已經配置完成了。 測試:curl https://domain:7443 便可,若是多節點配置直接配置443就ok了。

說明:當僅一臺服務器時沒法監聽443端口,需使用非被佔用的端口如7443,訪問域名就是https://domain:7443 若是計算節點和管理節點不在同一臺服務器上,便可監聽443端口。 https://domain

0x03 END

配置到這裏,雲幫https已經配置完成了。若是後期有什麼問題,能夠回帖或相關羣組裏反饋。

相關文章
相關標籤/搜索