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


問題描述

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

我正在使用 nginx 作為代理服務器。我的應用程序有一個功能,用戶可以使用他們自己的域而不是我的域。為此,他們需要將他們的 CNAME 指向我的域。

這是我的 Nginx 配置

server {
server_name scan.mydomain.com anonymous.mydomain.com "";
access_log /etc/nginx/log/local‑wc.access.log;
error_log /etc/nginx/log/local‑wc.error.log;

location / {
root /var/www/html/qcg‑scanning‑frontend/dist/webapp/;
index index.html;
try_files $uri $uri/ /index.html;
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_set_header X‑Forwarded‑Protocol $scheme;
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/anonymous.mydomain.com‑0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/anonymous.mydomain.com‑0001/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options‑ssl‑nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl‑dhparams.pem; # managed by Certbot
}

server {
if ($host = scan.mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = anonymous.mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

server_name scan.mydomain.com anonymous.mydomain.com "";
listen 80;
return 404; # managed by Certbot
}
</code></pre>

當使用我的域 scan.mydomain 瀏覽時,此配置工作正常。 comanonymous.mydomain.com 但使用像 new.example.com 這樣的任何指向域,它會給出 404 頁面(可能是由於 return 404 語句)。

對於 SSL,我使用lets‑encrypt certbot。

如何配置為

  1. 允許流量從所有 CNAME 指向的域到我的服務器?

  2. 參考解法

    方法 1:

    I used CaddyServer which is far better than nginx and satisfies all requirements.

    https://caddyserver.com/

    Features of Caddy

    • Support for third party domain CNAME pointing
    • JSON based configuration
    • API support for the configuration
    • On‑demand TLS
    • Default serves SSL/TLS to all the domains in the production server
    • No hassle to install and manage SSL certificates for the domains.

    (by Anuj TBEAnuj TBE)

    參考文件

    1. Nginx allow traffic from any domain (CC BY‑SA 2.5/3.0/4.0)

#Certbot #SSL #lets-encrypt #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)







留言討論