我自己项目有个需求一个服务器上部署了两个项目。
项目A 端口号:8080
项目B 端口号:8081
通过nginx反向代理映射端口号80,配置两个server。通过不同域名转发到对应的具体IP地址+端口号上。
项目A对应域名:8080.itmayiedu.com
项目B对应域名:8081.itmayiedu.com
nginx反向代理配置:
server {
listen 80;
server_name 8080.itmayiedu.com;
location / {
proxy_pass http://www.baidu.com;
index index.html index.htm;
}
}
server {
listen 80;
server_name 8081.itmayidu.com;
location / {
proxy_pass http://www.itmayiedu.com;
index index.html index.htm;
}
}
浏览器输入地址:8080.itmayiedu.com 结果进入了http://www.baidu.com;
浏览器输入地址:8081.itmayiedu.com 结果还是进入了http://www.baidu.com;
大家帮忙看一下,这是为什么输入不同的域名,怎么nginx都转向到了第一个server? 都跳转到了http://www.baidu.com 大家看看我哪里配置错误了?
通过主机头区分不同域名
https://www.markdream.com/technologies/server/nginx-config-null-host.shtml?replytocom=7
server {
2 listen 80;
3 gzip on;
4 gzip_min_length 1000;
5 gzip_proxied expired no-cache no-store private auth;
6 gzip_types text/plain text/css application/xml application/json application/javascript application/xhtml+xml;
7
8 server_name www.gxs.cn www.abc.cn www.def.cn;
9
10 index index.php index.html index.htm;
你只需要修改 server_name 后面,增加几个自己需要的域名即可
看着好像没啥问题。。。根据你的配置 你的nginx可能把第二个先重定向到http://www.itmayiedu.com然后再重定向到百度了 你把第二个里面http://www.itmayiedu.com换成其他域名下的试试?