node.js - Node : Set different domain name on different port

标签 node.js nginx dns port digital-ocean

我已经在 Node 中创建了我的网站。我对不同的模块使用不同的端口。

喜欢 http://localhost:5555/ 这是管理员的,

http://localhost:5050/ 这是用于客户端访问。'

我正在使用 Digitalocean Ubuntu 服务器,并且我已从 Godaddy 购买了域名。

我想在不同的端口上设置不同的域。

喜欢

http://localhost:5555/ 应为“http://admin.example.com ”。

http://localhost:5050/ 应为“http://example.com ”。

我在 Ubuntu 中尝试过使用 nginx 但没有任何用处。

请帮助我。提前致谢。

最佳答案

您的 nginx 配置文件中需要两个 server 配置,一个用于 admin 子域,另一个用于 example.com 本身。它应该看起来像这样:

    server {
    listen          80 default;
    server_name     example.com .example.com ;

    location / {

            proxy_pass http://localhost:5050;
            proxy_pass_header Server;
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $remote_addr;
    }

   server {
    listen          80;
    server_name     admin.example.com;

    location / {

            proxy_pass http://localhost:5555;
            proxy_pass_header Server;
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $remote_addr;
    }
}

关于node.js - Node : Set different domain name on different port,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31545798/

相关文章:

angularjs - 使用 nginx 和 ssl 配置 prerender.io

azure - 如何将相同的通配符主机名添加到多个Azure Web应用程序?

c# - 如何在 .NET 中解析 UDP 数据包?

angularjs - 使用 multipartFile 上传图像的注册表单

javascript - MEAN Stack 应用程序结构

javascript - 运行 Grunt 任务之前的确认

javascript - WebStorm 自动完成 Mongoose 模式字段

ruby-on-rails - 在 Rails 2.3.12 和 HTTPS 中安装机架应用程序失败

nginx - Spring Boot(ConfigServer)一直在重启

redirect - 子域使用 SRV 重定向到特定端口?