溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么在云幫上配置https

發(fā)布時間:2021-08-17 14:01:09 來源:億速云 閱讀:163 作者:chen 欄目:云計算

這篇文章主要介紹“怎么在云幫上配置https”,在日常操作中,相信很多人在怎么在云幫上配置https問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么在云幫上配置https”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

序 相關組件介紹

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

  • console模塊

即云幫(ACP)控制臺模塊,為用戶提供可視化Web操作界面,監(jiān)聽443端口即可,對證書需求:域名證書即可。

  • openresty模塊

即云幫負載均衡模塊。云幫所有的對外服務都配置在負載均衡上,都是通過負載均衡轉發(fā)到對應的應用與服務。大部分情況下監(jiān)聽443端口即可,如果單節(jié)點監(jiān)聽非占用端口即可。對證書需求:因為涉及的域名較多,這里我們選擇泛域名證書。

那么接下來就說說如何具體去配置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

特別說明:回車之后會讓填寫一些信息,這些適當根據(jù)提示填寫。但是最重要的就是要求Common Name填寫慎重,您需要輸入與您的服務器關聯(lián)的域名或您的服務器的公共IP地址。

demo如下:

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同原配置里的監(jiān)聽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都是支持的。如果想強制跳轉修改監(jiān)控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配置已經(jīng)完成。 測試:

 [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/

配置計算節(jié)點的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;
 #其他保持不變。

這里監(jiān)聽的是7443,因為我的是單節(jié)點部署的,443端口已經(jīng)被其他服務監(jiān)聽,故使用7443端口。 配置完以上的,重啟openresty即可。

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

配置到這里,應用的https已經(jīng)配置完成了。 測試:curl https://domain:7443 即可,如果多節(jié)點配置直接配置443就ok了。

說明:當僅一臺服務器時無法監(jiān)聽443端口,需使用非被占用的端口如7443,訪問域名就是https://domain:7443 如果計算節(jié)點和管理節(jié)點不在同一臺服務器上,即可監(jiān)聽443端口。 https://domain

0x03 END

配置到這里,云幫https已經(jīng)配置完成了。

到此,關于“怎么在云幫上配置https”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI