為 AWS 中託管的網站設置 HTTPS,但指向局域網中的 webAPI (Setting up HTTPS for a website hosted in AWS, but points to a webAPI in the local area network)


問題描述

為 AWS 中託管的網站設置 HTTPS,但指向局域網中的 webAPI (Setting up HTTPS for a website hosted in AWS, but points to a webAPI in the local area network)

我正在開展一個項目,我們在 AWS 上託管一個網頁。該網頁從局域網計算機名稱IE:Server‑24.Local調用webAPI。這種方法可確保數據不會離開網絡,因為 Server‑24.Local 不會暴露給 Internet。到目前為止,這種方法效果很好。但是,當我通過 certbot 啟用 HTTPS 時遇到問題:

如果我嘗試將 proxy_pass nginx 傳遞到本地主機上 AWS 中託管的 webapi,HTTPS 可以正常工作。但是,如果我 proxy_pass nginx 到 Server‑24.Local,它會返回跨域錯誤。兩個 webAPI 都支持 CORS。

有人有什麼建議嗎?


參考解法

方法 1:

you can research about Nginx CORS enabled in internet... It's about end user browser security in chrome etc...

Here is an example, put it inside location tag {}

#
# Wide‑open CORS config for nginx
#
location / {
     if ($request_method = 'OPTIONS') {
        add_header 'Access‑Control‑Allow‑Origin' '*';
        add_header 'Access‑Control‑Allow‑Methods' 'GET, POST, OPTIONS';
        #
        # Custom headers and headers various browsers *should* be OK with but aren't
        #
        add_header 'Access‑Control‑Allow‑Headers' 'DNT,User‑Agent,X‑Requested‑With,If‑Modified‑Since,Cache‑Control,Content‑Type,Range';
        #
        # Tell client that this pre‑flight info is valid for 20 days
        #
        add_header 'Access‑Control‑Max‑Age' 1728000;
        add_header 'Content‑Type' 'text/plain; charset=utf‑8';
        add_header 'Content‑Length' 0;
        return 204;
     }
     if ($request_method = 'POST') {
        add_header 'Access‑Control‑Allow‑Origin' '*';
        add_header 'Access‑Control‑Allow‑Methods' 'GET, POST, OPTIONS';
        add_header 'Access‑Control‑Allow‑Headers' 'DNT,User‑Agent,X‑Requested‑With,If‑Modified‑Since,Cache‑Control,Content‑Type,Range';
        add_header 'Access‑Control‑Expose‑Headers' 'Content‑Length,Content‑Range';
     }
     if ($request_method = 'GET') {
        add_header 'Access‑Control‑Allow‑Origin' '*';
        add_header 'Access‑Control‑Allow‑Methods' 'GET, POST, OPTIONS';
        add_header 'Access‑Control‑Allow‑Headers' 'DNT,User‑Agent,X‑Requested‑With,If‑Modified‑Since,Cache‑Control,Content‑Type,Range';
        add_header 'Access‑Control‑Expose‑Headers' 'Content‑Length,Content‑Range';
     }
}

you can help look at here [https://enable‑cors.org/server_nginx.html] ...

hopefully this help you...

(by MrSeangumelaragum)

參考文件

  1. Setting up HTTPS for a website hosted in AWS, but points to a webAPI in the local area network (CC BY‑SA 2.5/3.0/4.0)

#Certbot #amazon-ec2 #nginx






相關問題

certbot-auto /letsencrypt 為指向同一服務器的多個域設置一個密鑰 (certbot-auto / letsencrypt setting up one key for multiple domains pointing to the same server)

certbot 工作時 Phpseclib 早期執行 (Phpseclib early execution while certbot working)

“httpd.service 的作業失敗,因為控制進程以錯誤代碼退出。” 我該如何解決? ("Job for httpd.service failed because the control process exited with error code." How do I fix this?)

無法使用 certbot renew/Letsencrypt 續訂證書 (Cannot renew certificates with certbot renew/Letsencrypt)

為 AWS 中託管的網站設置 HTTPS,但指向局域網中的 webAPI (Setting up HTTPS for a website hosted in AWS, but points to a webAPI in the local area network)

docker 發送內部 cerbot 日誌文件到主機 journald (docker send internal cerbot log file to host journald)

Nginx 允許來自任何域的流量 (Nginx allow traffic from any domain)

如何有效地為 2 個遠程節點使用 Kubernetes (How to use Kubernetes effectively for 2 distant nodes)

如何在 docker 映像中創建目錄? (How can I make dir inside docker image?)

更新 Certbot 時出現“連接超時(可能是防火牆問題)” ("Timeout during connect (likely firewall problem)" while renewing Certbot)

安裝certbot後找不到nginx頁面錯誤 (nginx page not found error after certbot installation)

Nginx 和 certbot 的 ERR_SSL_PROTOCOL_ERROR (ERR_SSL_PROTOCOL_ERROR with Nginx & certbot)







留言討論