简体   繁体   English

Nginx从一个域重定向到动态域?

[英]Nginx redirect from one domain to dynamic domain?

I have two instances of nginx server running one with corporate ip and second with internal ip .I want a link from external nginx get redirected to internal nginx server and use external nginx as gateway. 我有两个nginx服务器实例,一个运行corporate ip ,另一个运行internal ip 。我希望将来自外部nginx的链接重定向到内部nginx服务器,并使用外部nginx作为网关。 Also need to make sure that internal nginx running on dynamic IP 还需要确保内部Nginx在dynamic IP运行

Tried to use variable for dynamic IP as shown in code snippet 尝试将变量用于动态IP,如代码片段所示

 location /route/(?<section>.+){
      proxy_bind 172.31.*.*;
      proxy_pass http://$section/single-table-view;
      proxy_set_header Host $http_host;
}

You need to configure nginx as mentioned below: 您需要按如下所述配置nginx:

If you want to redirect your External nginx to Internal nginx you should configure your External server like: 如果要将外部nginx重定向到内部nginx ,则应将外部服务器配置为:

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

        location / {

                proxy_pass http://InternalNginxIpAddress:PortYouWant;

                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

Now each request from External nginx will be forwarded to Internal nginx, where your Internal nginx server is set as 现在,来自外部nginx的每个请求都将转发到内部nginx,在此处将内部nginx服务器设置为

proxy_pass http://localhost:PortYouWant;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM