how to use different domain names for different processes running on same server

huangapple go评论97阅读模式
英文:

how to use different domain names for different processes running on same server

问题

假设我有三个不同的运行网站。一个运行在端口3000上的Node.js应用,一个运行在端口80上的Apache/PHP应用,还有一个运行在端口5000上的Go应用。

我该如何为这三个端口设置不同的域名?

我考虑在端口80上建立一个基本的路由系统,所有的域名都指向这个端口,然后程序根据URL进行重定向到正确的端口。这种方法可行吗?还有更好的方法吗?

谢谢。

英文:

Assume I have three different sites running. Node.js app on port 3000, Apache/PHP on port 80, and then a Go app on port 5000.

How can I have three different domain names that go to each port?

I was thinking of a basic route system on port 80 that all domains refer to, then the program looks at url and redirects to correct port. Is that recommended? Is there a better way?

Thanks

答案1

得分: 1

如果你已经在使用Nginx,你可以非常容易地为不在80端口上的应用程序设置基于名称的反向代理虚拟主机:

server {
    listen *:80;
    server_name nodeapp.mydomain.com;
    location / {
        proxy_pass http://localhost:3000;
    }
}

server {
    listen *:80;
    server_name goapp.mydomain.com;
    location / {
        proxy_pass http://localhost:5000;
    }
}
英文:

If you're already using Nginx, you can very easily set up named-based reverse proxy vhosts for the apps that aren't on port 80:

server {
    listen *:80;
    server_name nodeapp.mydomain.com;
    location / {
        proxy_pass http://localhost:3000;
    }
}

server {
    listen *:80;
    server_name goapp.mydomain.com;
    location / {
        proxy_pass http://localhost:5000;
    }
}

答案2

得分: 0

如果你在80端口上运行的只是一个代理层,你可以使用caddy,它本身就是用Go语言编写的。你的Caddyfile应该像这样:

nodeapp.mydomain.com {
    proxy / localhost:3000
}

goapp.mydomain.com {
    proxy / localhost:5000
}

如果不是的话,你仍然可以使用caddy,只需将你的PHP应用程序移到不同的端口上。

我建议使用caddy,因为它的创建者在各个方面都推崇安全性(如果你的网站适用的话,你会注意到它会自动提供https)。配置(在Caddyfile中完成)通常很简短且非常容易理解。Caddy有广泛的用例,并且可以使用插件来完成几乎任何你能想到的任务。

英文:

If what you're running on port 80 is just a proxy layer, you could instead use caddy, which is itself written in Go. Your Caddyfile would like something like this:

nodeapp.mydomain.com {
    proxy / localhost:3000
}

goapp.mydomain.com {
    proxy / localhost:5000
}

If not, you could still use caddy and just move your PHP application to a different port.

I suggest caddy because its creator pushes for security everywhere (you will notice you get automatic https if your site is applicable). The configuration (done in the Caddyfile) is also usually short and very easy to understand. Caddy has a wide range of use cases and can come with plugins to do just about anything you can think up.

huangapple
  • 本文由 发表于 2017年6月28日 22:50:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/44805907.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定