【问题标题】:Setting up proxy for both QA and WWW version of website with NGINX使用 NGINX 为网站的 QA 和 WWW 版本设置代理
【发布时间】:2020-08-26 07:48:40
【问题描述】:

我正在尝试让我的域连接到我的服务器。当域为 www.website.com 时,我的网站可以正常运行,但是当我尝试使用 qa.webite.com 时它不起作用。我知道我的上游开发人员正在工作,因为我能够使其与 IP1 一起工作。我的问题是我无法让它与 IP2 的第二个服务器块一起使用。

这是我在 Google Domains 上的设置。

这是我的 nginx.conf。

worker_processes auto;

error_log /home/ubuntu/nginx_error.log;
pid /home/ubuntu/nginx.pid;

events {
        worker_connections 1024;
}

http {
  proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=2g inactive=60m use_temp_path=off;

  upstream master {
    ip_hash;
    server 127.0.0.1:6001;
    server 127.0.0.1:6002;
    keepalive 100;
  }

  upstream dev {
    ip_hash;
    server 127.0.0.1:6003;
    server 127.0.0.1:6004;
    keepalive 100;
  }

// This works
  server {
    listen IP1:80;
    server_name IP1;

    location / {
      resolver 8.8.8.8;

      proxy_set_header Host  $host;
      proxy_set_header X-Forwarded-For $remote_addr;

      proxy_cache my_cache;
      proxy_cache_min_uses 3;
      proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
      proxy_cache_background_update on;
      proxy_cache_lock on;
      proxy_pass http://master;
    }

    location /docker {
      proxy_pass http://localhost:8080;
    }
  }

// This never gets hit.
  server {
    listen IP2:80;
    server_name IP2;

    location / {
      resolver 8.8.8.8;

      proxy_set_header Host  $host;
      proxy_set_header X-Forwarded-For $remote_addr;

      proxy_cache my_cache;
      proxy_cache_min_uses 3;
      proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
      proxy_cache_background_update on;
      proxy_cache_lock on;
      proxy_pass http://dev;
    }
  }
}

【问题讨论】:

    标签: amazon-web-services nginx nginx-config google-domains


    【解决方案1】:

    我可以在我的云中进行这样的配置。

    在你的server that never gets hit

    server {
      listen 80 default_server;
      server_name qa.mavega.org;
    
    location / {
      resolver 8.8.8.8;
    
      proxy_set_header Host  $host;
      proxy_set_header X-Forwarded-For $remote_addr;
    
      proxy_cache my_cache;
      proxy_cache_min_uses 3;
      proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
      proxy_cache_background_update on;
      proxy_cache_lock on;
      proxy_pass http://dev;
      }
    }
    

    你在 google 的配置没问题。

    记得更改 nginx 配置后, 进行语法检查:

    sudo nginx -t
    

    如果没问题,重启 nginx 应用新配置。

    sudo nginx -s reload
    

    你的谷歌配置在我看来还不错。在它工作后,您可以删除一些条目。

    【讨论】:

    • 我会尝试看看这是否可行,但我真的想使用 IP,因为我将有多个域指向同一个 ip。我的应用根据我传递给它的主机名呈现。
    • 这不起作用。我感觉它是 AWS 的一个问题,但我也一直回到那个服务器块。
    【解决方案2】:

    原来我必须在我的 aws 机器上设置 IP,而不仅仅是在浏览器中。

    本指南应该可以帮助https://bobcares.com/blog/an-easy-guide-to-setup-amazon-ec2-multiple-ips/2/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 2016-11-07
      • 2020-02-29
      相关资源
      最近更新 更多