简体   繁体   English

节点:在不同的端口上设置不同的域名

[英]Node : Set different domain name on different port

I have created my website in node. 我已经在node中创建了我的网站。 where I am using different port for different modules. 我在不同的模块上使用不同的端口。

like http://localhost:5555/ this is for admin, http://localhost:5555/这是给管理员的,

http://localhost:5050/ this is for client access.' http://localhost:5050/ ,用于客户端访问。”

I am using Digitalocean Ubuntu server and I have bought domains from Godaddy . 我正在使用Digitalocean Ubuntu服务器,并且已经从Godaddy购买了域名。

I want to set different domain on different port. 我想在不同的端口上设置不同的域。

like 喜欢

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

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

I have tried with nginx in Ubuntu but doesn't get any useful. 我曾在Ubuntu中尝试过nginx ,但没有任何用处。

Please help me . 请帮我 。 Thanks in advance. 提前致谢。

You need two server configs in your nginx config file, one for the admin subdomain and one for example.com itself. 您需要在nginx配置文件中进行两个server配置,一个用于admin子域,另一个用于example.com本身。 It should look something like this: 它看起来应该像这样:

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

and

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

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

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