簡體   English   中英

Droplet上的Nginx服務器IP重定向到特定域

[英]Nginx server IP on droplet redirect to specific domain

我在DigitalOcean Droplet上使用Nginx運行2個域

Domain1是傳遞給localhost:3000的節點應用程序代理。 很棒!

Domain2是一個靜態站點,也可以正常運行。

但是,每當我加載服務器IP(沒有端口3000)時,我總是會重定向到domain1(節點應用程序)。

Domain1是一種私有站點,而domain2是公共博客。

我的問題是,為了使人們在加載IP時重定向到domain2,我必須進行哪些更改,以保護domain1不會輕易訪問。 (易於查找VPS IP)

這是“可用站點”文件:

節點應用程序:

server {
    listen [::]:80;
    listen 80;


server_name www.domain1.com domain1.com;

# and redirect to the https host (declared below)
return 301 https://domain1.com$request_uri;
}

server {
    listen 443;
    server_name domain1.com www.domain1.com;

    ssl on;
    # Use certificate and key provided by Let's Encrypt:
    ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';


    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://localhost:3000/;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_cache_bypass $http_upgrade;
            proxy_redirect off;
    }
}

和靜態的:

server {
    listen [::]:80;
    listen 80;


   server_name www.domain2.com domain2.com;

   root /var/www/html/domain2;
   index index.html index.htm;


   return 301 https://domain2.com$request_uri;
}

server {

   listen [::]:443 ssl;
   listen 443 ssl;

   root /var/www/html/domain2;

   index index.html index.htm;

   ssl_certificate /etc/letsencrypt/live/domain2.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/domain2.com/privkey.pem;
}

任何幫助/提示表示贊賞,在此先感謝您!

因此,您的兩個域都在端口80上進行監聽。當您的nginx服務器收到請求時,它會先檢查域,然后再確定其路由...但是由於沒有域可以檢查,只需輸入ip地址即可,它將默認到第一個列出的服務器(我猜是domain1)

您可以通過聲明默認服務器或更改其列出順序來規避此問題。

我希望我能有所幫助。 一個很好的小參考http://nginx.org/en/docs/http/request_processing.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM