反向代理到使用NGINX映射到URL路径的两个不同的服务器

时间:2019-09-23 05:30:23

标签: nginx reverse-proxy digital-ocean nginx-location nginx-reverse-proxy

我也搜索了Google和StackOverflow,但找不到确切的需求。我也尝试了3天,但还是无法正常工作。

我在DigitalOcean上有3个墨滴。每个人都可以通过私有IP相互访问。

App1托管于10.139.207.6:3000 App2托管在10.139.207.8:80

这是我的nginx配置:

upstream app1 {
    server 10.139.207.6:3000;
}
upstream app2 {
    server 10.139.207.8;
}

server {
    server_name test.xyz.com;
    listen 80;

    location / {
        proxy_pass http://app1/;
    }
    location /app2/ {
        proxy_pass http://app2/;
    }

}

访问test.xyz.com时收到无效的主机错误。

您能告诉我正确的方法吗?

编辑

我将我的nginx配置更改为此,并且现在可以正常工作,但是有一个奇怪的问题:

server {

  server_name test.xyz.com;

  location / {
      proxy_pass http://10.139.207.6:3000/;
  }
  location /blogs {
      proxy_pass http://10.139.207.8/$args;
  }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/proxy.koolkanya.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/proxy.koolkanya.com/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 = proxy.koolkanya.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  listen 80;
  listen [::]:80;

  server_name proxy.koolkanya.com;
    return 404; # managed by Certbot


}

现在,我可以打开wordpress(app2)和reactjs npm(app1),但是app2链接不起作用(因为它们是wordpress的永久链接)。

0 个答案:

没有答案