我试图让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/;
}
}
}
答案 0 :(得分:0)
我最终为每个客户端应用程序创建了一个单独的服务器上下文,并使用重定向来处理来自根上下文的路由。
用户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 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/;
}
}
}