Configure Nginx reverse proxy subdomains with dynamic DNS

时间:2016-02-12 21:41:40

标签: nginx dns

I have a small lab at home with several virtual machines that each has a web application:

Meteor.publish("userData", function(){
  return Meteor.users.find({_id: this.userId});
});

Meteor.publish("users", function(){
    return Meteor.users.find({ "status.online": true })
});

  Meteor.methods({
    sendMessage: function (chat) {
      Chats.insert({
        chat: chat,
        createdAt: new Date(),
        username: Meteor.user().profile.username,
        avatar: Meteor.user().profile.avatar,
      });
    },
  });

I also have a free dynamic DNS service (noip.com) that I configured on my internet router. address for example : home.ddns.net

is it possible to use Nginx as a reverse proxy to serve each web application as a subdomain to the home domain/subdomain ?

like this:

http://vm1:8080

http://vm2:8081

http://vm3:8082

or even this: (use port 80) ?

http://app1.home.ddns.net:8080 => http://vm1:8080

http://app2.home.ddns.net:8081 => http://vm2:8081

if that is not possible, can I use it like this? :

http://app1.home.ddns.net => http://vm1:8080

http://app2.home.ddns.net => http://vm2:8081

my question seems simple but I was not able to find an answer online and on stackoverflow :(

Thanks

2 个答案:

答案 0 :(得分:0)

所有变种都是可能的,但第二种变体最简单。

server {
    listen 80;
    server_name app1.home.ddns.net;
    location / {
        proxy_pass http://vm1:8080;
    }
}

server {
    listen 80;
    server_name app2.home.ddns.net;
    location / {
        proxy_pass http://vm2:8081;
    }
}

请参阅http://nginx.org/en/docs/http/request_processing.html

答案 1 :(得分:0)

我在NO-IP子域(*.hopto.org下管理自定义服务器,而不是*.ddns.net,但基本上由同一家公司运行),这似乎是不可能的。尽管Alexey's answer关于nginx配置可能是正确的,但截至今天,NO-IP不允许子子域。

有关详细信息,请参阅this answer的最后一部分。但基本上这意味着允许每个人自己成为 re-sellers