根據 cookie 的值,我有以下地圖:
map $cookie_version $version_host {
default 172.17.0.1:8001;
2.65.1 172.17.0.1:8001;
2.65.2 172.17.0.1:8003;
}
但是,對于標頭的值,我需要相同的映射:
map $http_app_version $version_api_host {
default 172.17.0.1:8001;
2.65.1 172.17.0.1:8001;
2.65.2 172.17.0.1:8003;
}
有沒有辦法不復制地圖?
我的服務器塊:
server {
listen 443 ssl;
ssl_certificate /etc/ssl/nexello.crt;
ssl_certificate_key /etc/ssl/nexello.key;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-FORWARDED-FOR $remote_addr;
charset utf-8;
location / {
# Web based access
# Cookies are used instead of a header because the request passes through here before any javascript can even set a Header.
if ($cookie_token) {
proxy_pass https://$version_host;
}
# API based access
# Here we use headers because anyone that is using the API has full control of the headers.
if ($http_authorization) {
proxy_pass https://$version_api_host;
}
# Auth
# In case there is no header or cookie we assume that it has no access token and should be redirected to the auth machine.
proxy_pass https://172.17.0.1:7001;
}
}
uj5u.com熱心網友回復:
你可以使用
map $cookie_version$http_app_version $version_host {
default 172.17.0.1:8001;
# your complicated regex here since two variables will be concatenated.
}
并在 proxy_pass 中使用 $version_host。
也是題外話,因為您使用if它時要小心
https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
uj5u.com熱心網友回復:
我在某種程度上解決了這個問題,因為雖然仍然有兩張地圖,但選項存盤在另一個檔案中,所以不會有任何重復:
map $cookie_version $version_cookie_host {
include /etc/nginx/versions.conf;
}
map $http_authorization $version_header_host {
include /etc/nginx/versions.conf;
}
內容/etc/nginx/versions.conf:
default 172.17.0.1:8001;
2.65.1 172.17.0.1:8001;
2.65.2 172.17.0.1:8003;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/505161.html
標籤:nginx
上一篇:Nginx回應404notfoundonDjangomediaURLinpreprod,devok
下一篇:帶有nginx的Dockerizedreactsocket.io客戶端已連接但未發送到反向代理uvicornasgi服務器(客戶端到服務器,反之亦然)
