我想用同一个域的Nginx托管2个不同的节点应用程序,但是遇到了一些麻烦.我想拥有:
mydomain.com指向节点app firstApp和otherapp.mydomain.com指向节点app otherapp
现在,我可以访问firstApp,但我无法通过otherapp.mydomain.com访问otherapp.
我对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的配置如下所示:
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目录中创建了两个配置,它们都链接在启用站点的目录中,并且我已经重新启动了Nginx.有人能告诉我我做错了什么吗?
谢谢,
斯瓦拉杰
最佳答案
原文链接:https://www.f2er.com/nginx/434343.html