Home >Backend Development >PHP Tutorial >Nginx+Tomcat realizes single IP and multiple domain name access?

Nginx+Tomcat realizes single IP and multiple domain name access?

WBOY
WBOYOriginal
2016-08-08 09:24:011084browse
环境说明:
    192.168.91.51部署nginx
    192.168.91.83部署tomcat1(端口8080,部了appa应用)和tomcat2(端口:9080,部了appb应用)
预期目的:
    访问a.cn,解析到tomcat1上的appa;
    访问b.cn,解析到tomcat2上的appb;
Nginx配置文件如下:
server {  
    listen       80;
    server_name  *.a.cn; 
    location / {  
        proxy_pass http://192.168.91.83:8080/appa/;  
        proxy_set_header   Host    $host;  
        proxy_set_header   X-Real-IP   $remote_addr;  
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
    }  
}
server {  
    listen       80;
    server_name  *.b.cn;
    location / {  
        proxy_pass http://192.168.91.83:9080/appb/;  
        proxy_set_header   Host    $host;  
        proxy_set_header   X-Real-IP   $remote_addr;  
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
    }  
}

但是访问域名后提示:502错误,这是为什么呢?


<pre class="brush:php;toolbar:false">没有环境,你如下测试,其中3是增加一个Upstream模块。默认就有的。:
1,将Proxy_pass最后面的appa/中的/去掉。
2,在Tomcat中将项目名隐藏掉,搜索一下即可。直接ip+端口。当然后面也不要加/
3,在Nginx中使用Upstream模块。
比如Proxy引用,结合2中,将项目名隐藏掉。

 upstream a.server
     {
     ip_hash;
     server 192.168.91.83:9080;
     }
其他一样

The above introduces how Nginx+Tomcat can achieve single IP and multiple domain name access? , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn