在代理傳遞中使用變數時,Nginx 配置會導致過多的重定向。這是嘗試使用 NGINX 反向代理私有子網中的資源。反向代理在代理傳遞中直接使用 DNS 記錄時作業正常,但在傳遞變數時會導致過多的重定向。
NGINX 配置:不作業
server {
listen 443 ssl;
access_log /var/log/nginx/reverse-access.log;
error_log /var/log/nginx/reverse-error.log;
server_name $host;
rewrite ^/$ https://$host/_dashboards redirect;
ssl_certificate /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
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;
set $domain_endpoint "${elasticsearch_endpoint}";
set $cognito_endpoint "${cognito_host}";
location /_dashboards {
# Forward requests to Dashboards
proxy_pass https://$domain_endpoint/_dashboards;
# Handle redirects to Cognito
proxy_redirect https://$cognito_endpoint https://$host;
# Update cookie domain and path
proxy_cookie_domain $domain_endpoint $host;
proxy_cookie_path / /_dashboards/;
# Response buffer settings
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
location ~ \/(log|sign|fav|forgot|change|saml|oauth2) {
# Forward requests to Cognito
proxy_pass https://$cognito_endpoint;
# Handle redirects to Dashboards
proxy_redirect https://$domain_endpoint https://$host;
# Update cookie domain
proxy_cookie_domain $cognito_endpoint $host;
}
}
作業配置的唯一區別。是不是proxy_pass第一個location /_dashboards是直接給DNS記錄這樣的
location /_dashboards {
# Forward requests to Dashboards
proxy_pass https://vpc-aws-blah-blah-blah.com/_dashboards;
在瀏覽器中查看網路流量時。請求似乎是相同的。redirect_uri它使用 url 引數向登錄端點發出初始 POST 請求。
不同之處在于,在初始 POST 之后,作業版本發出一個 GET 請求,而非作業版本發出重復的 GET 請求
uj5u.com熱心網友回復:
從檔案中:
如果 proxy_pass 指令是用一個 URI 指定的,那么當一個請求被傳遞到服務器時,與該位置匹配的規范化請求 URI 的部分將被指令中指定的 URI 替換
你/_dashboards在locationand中都有proxy_pass,因此替換不會改變。proxy_pass因此,您可以從陳述句中洗掉可選的 URI 部分。
此外,在同一個檔案中:
在 proxy_pass ... 中使用變數時,如果指令中指定了 URI,則按原樣傳遞給服務器,替換原始請求 URI。
因此,當您開始使用變數時,如果原始請求是/_dashboards/foo,則上游服務器只會收到/_dashboards。
最簡單的解決方案是/_dashboards從proxy_pass陳述句中洗掉。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415693.html
標籤:
