我已经在 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/