【问题标题】:Node : Set different domain name on different portNode : 在不同的端口上设置不同的域名
【发布时间】:2015-10-11 07:19:38
【问题描述】:

我已经在 node.js 中创建了我的网站。我为不同的模块使用不同的端口。

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

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

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

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

喜欢

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

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

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

请帮帮我。提前致谢。

【问题讨论】:

  • 我在 Ubuntu 上使用 nginx 进行了此操作,因此没有遇到任何问题。你遇到了什么问题?

标签: node.js nginx dns port digital-ocean


【解决方案1】:

您的 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;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-06
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 2015-02-07
    • 2020-07-19
    • 2015-03-15
    相关资源
    最近更新 更多