我尝试将流量从nginx代理(PROXY_IP)重定向到Wildfly实例(WILDFLY_IP)。可以使用网址http://WILDFLY_IP:8080/PROJECT_NAME访问java项目。我想隐藏项目名称,用户可以访问http://PROXY_IP/并查看相同内容。 nginx代理也用于强制执行HTTPS。
我的配置如下:
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name PROXY_IP;
ssl_certificate xxxx;
ssl_certificate_key xxxx;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/proxy.access.log;
error_log /var/log/nginx/proxy.error.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://WILDFLY_IP:8080/PROJECT_NAME;
proxy_read_timeout 90;
proxy_redirect http://WILDFLY_IP:8080/PROJECT_NAME https://PROXY_IP;
}
location /PROJECT_NAME {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://WILDFLY_IP:8080/PROJECT_NAME;
proxy_read_timeout 90;
proxy_redirect http://WILDFLY_IP:8080/PROJECT_NAME https://PROXY_IP;
}
}
配置会将流量转发到Wildfly实例并强制执行https,但会将用户从http://PROXY_IP/重定向到https://PROXY_IP/PROJECT_NAME
答案 0 :(得分:0)
我认为你可以通过重写来做到这一点。
location /PROJECT_NAME {
....
rewrite /PROJECT_NAME/(.*) /$1 break;
....
}