gpt4 book ai didi

tomcat - Nginx 反向代理单个 tomcat 实例上的多个应用程序

转载 作者:行者123 更新时间:2023-11-28 23:17:13 25 4
gpt4 key购买 nike

我试图让 nginx 从不同的 server_names 反向代理 tomcat 服务器上的多个应用程序。例如,客户端 a 将被发送到位于 app-a 的 tomcat 上的应用程序。

相反,浏览器不会接收 js 文件、图像或 css。它只是获取 HTML。

user  www-data;

error_log /var/log/nginx/error.log warn;
pid /run/nginx.pid;

worker_processes 2;

events {
worker_connections 1024;
multi_accept on;
}

http {
client_body_buffer_size 10m;
client_header_buffer_size 1m;
client_max_body_size 20m;
large_client_header_buffers 2 1m;

keepalive_timeout 300s;
send_timeout 300s;

proxy_http_version 1.1;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_bind $server_addr;

proxy_buffering off;
chunked_transfer_encoding off;

# kill cache
#add_header Last-Modified $date_gmt;
#add_header Cache-Control 'private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;

# kill proxy cache, even if cached, don't try to use it
proxy_no_cache 1;
proxy_cache_bypass 1;

server {
listen 80;
listen [::]:80;

server_name ~^([\w\d-]+)\.app\.uat\.us\.pic\.com;

location / {
proxy_pass http://uat-client-appservers.us.pic.com:80/app-$1/;
}
location /app/ {
proxy_pass http://uat-client-appservers.us.pic.com:80/app-$1/;
}
location /app-handler/ {
proxy_pass http://uat-client-appservers.us.pic.com:80/app-handler-$1/;
}
}
}

最佳答案

我最终为每个客户端应用程序创建了一个单独的服务器上下文,并使用重定向来处理来自根上下文的路由。

用户 www 数据;

    error_log  /var/log/nginx/error.log warn;
pid /run/nginx.pid;

worker_processes 2;

events {
worker_connections 1024;
multi_accept on;
}

http {
client_body_buffer_size 10m;
client_header_buffer_size 1m;
client_max_body_size 20m;
large_client_header_buffers 2 1m;

keepalive_timeout 300s;
send_timeout 300s;

proxy_http_version 1.1;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_bind $server_addr;

proxy_buffering off;
chunked_transfer_encoding off;

# kill cache
#add_header Last-Modified $date_gmt;
#add_header Cache-Control 'private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
#if_modified_since off;
#expires off;
#etag off;

# kill proxy cache, even if cached, don't try to use it
proxy_no_cache 1;
proxy_cache_bypass 1;

server {
listen 80;
listen [::]:80;

server_name a.app.uat.us.pic.com;

location = / {
return http://a.app.uat.us.pic.com/app-a/;
}
location /app/ {
proxy_pass http://uat-client-appservers.us.pic.com:80/app-a/;
}
location /app-handler/ {
proxy_pass http://uat-client-appservers.us.pic.com:80/app-handler-a/;
}
}
}

关于tomcat - Nginx 反向代理单个 tomcat 实例上的多个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47806256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com