在同一域上使用Nginx服务多个节点应用 [英] Serving multiple node apps with nginx on same domain
问题描述
我想使用来自同一域的nginx托管2个不同的节点应用程序,并且遇到了一些麻烦.我想拥有:
I would like to host 2 different node applications with nginx from the same domain and am having some trouble. I would like to have:
mydomain.com 指向节点应用程序 firstApp ,而 otherapp.mydomain.com 指向节点应用程序 otherapp
mydomain.com point to node app firstApp and otherapp.mydomain.com point to node app otherapp
现在,我可以很好地访问 firstApp ,但不能通过otherapp.mydomain.com访问 otherapp .
Right now, I can access firstApp just fine, but I cannot access otherapp via otherapp.mydomain.com.
我的 firstApp 的配置如下:
upstream firstApp{
server 127.0.0.1:8123;
}
server{
server_name mydomain.com;
access_log /var/log/nginx/me.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://firstApp/;
proxy_redirect off;
}
}
我的 otherapp 配置看起来像这样:
My config for otherapp looks like this:
upstream otherapp{
server 127.0.0.1:8124;
}
server{
server_name otherapp.mydomain.com;
access_log /var/log/nginx/me.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://otherapp/;
proxy_redirect off;
}
}
我已经在nginx sites-available目录中创建了这两种配置,它们都在启用了sites的目录中链接,并且我已经重新启动了nginx.有人可以告诉我我在做什么错吗?
I have created both configurations in the nginx sites-available directory, they are both linked in the sites-enabled directory, and I have restarted nginx. Can someone tell me what I'm doing wrong?
谢谢, 斯瓦拉吉
推荐答案
只是发现了问题所在.尽管我的nginx配置正确,但是我尚未将所需的子域添加到域名提供者(namecheap)中.我在namecheap上添加了我的子域,现在一切正常.
Just found out what the problem was. Though my nginx configs were correct, I had not added my desired subdomain to my domain name provider (namecheap). I added my subdomain on namecheap, and everything is working correctly now.
这篇关于在同一域上使用Nginx服务多个节点应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!