【问题标题】:configuring multiple domains with nginx使用 nginx 配置多个域
【发布时间】:2018-05-21 04:10:45
【问题描述】:
首先,已经有一个服务器在 80 端口上运行(带有域,比如说 domainA.com ),我还有另一个域(domainB.com)。这就是我想要做的。
80 端口:domainA.com
3000 端口:domainB.com
所以如果我向 domainB.com 发出请求,它不应该重定向到 domainA.com:3000,但实际上应该在同一台服务器上工作。并且 DNS 服务器 ip 设置为与 domainA.com 连接的服务器相同(所以如果我去 domainB.com 它只是重定向到 domainA.com,我想我需要修复这部分但我不知道) .我怎样才能做到这一点?
【问题讨论】:
标签:
nginx
proxy
reverse-proxy
nginx-location
nginx-reverse-proxy
【解决方案1】:
server {
listen 80;
server_name domainA.com;
root /var/www/domainA;
}
server {
listen 3000;
server_name domainB.com ;
root /var/www/domainB;
}
您现在可以通过以下方式访问此站点:domainA.com 和 domainB.com:333
你也可以让他们都在端口 80 上监听:
nginx 可以检测到该请求来自哪个域并将请求重定向到该域:
server {
listen 80;
server_name domainA.com;
root /var/www/domainA;
}
server {
listen 80;
server_name domainB.com ;
root /var/www/domainB;
}
看到这个:nginx server_names
来源:diffrent domain on same ip