nginx is configured with multiple tomcat sharing port 80
- 2020-05-13 04:38:19
- OfStack
Scenario: project 1 in tomcat1, project 2 in tomcat2, two tomcats on the same server, need to share port 80 access
Note: this is different from cluster deployment, where one project is placed in multiple tomcat.
Here by nginx do reverse proxy, nginx please visit http: / / nginx org/en/download html download,
Modify server in conf/ nginx.conf as follows:
server {
listen 80;
server_name 192.168.1.197;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
# Add the following configuration
location /server1{
proxy_pass http://192.168.1.197:8081/server1;# Mainly here, this is tomcat1 Ports and items
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
root html;
index index.html index.htm;
}
location /server2{
proxy_pass http://192.168.1.197:8082/server2;# Mainly here, this is tomcat2 Ports and items </span>
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
root html;
index index.html index.htm;
}
Ok, then you can use the http: / / 192.168.1.197 / server1 and http: / / 192.168.1.197 server2 access services respectively