nginx - Nginx:需要 http_name 域的映射函数
问题描述
我们需要请求主机的域部分。
Fe:如果www1.domX.here是请求的主机,我们需要domX.here变量。
不工作:
map $http_host $this_dom {
default $http_host;
~^www1\.(?<this_dom>)$ $this_dom;
}
server {
server_name
www1.dom1.here
www1.dom2.here
www1.dom3.here
www1.dom4.here
www1.dom5.here;
location /somestuff {
# local content delivery
root /shared/somestuff;
}
location / {
return 301 https://www.$this_dom$request_uri;
}
}
此示例导致一个空域。
目前以这种方式解决了它:
if ($host ~* ^www1\.(.*)$) {
set $this_dom $1;
}
解决方案
感谢Ivan Shatsky,解决方案是:
map $host $this_domain {
default $host;
~www1\.(.*)$ $1;
}
推荐阅读
- typescript - 如何从共享其接口的对象实例化一个类?
- visual-studio-code - Visual Studio Code 中的 GIT 文件视图
- r - R stringR RegExp 策略,用于在没有先验知识的情况下对类似表达式进行分组
- javascript - 如何从 FullCalendar 中的事件获取弹出消息中事件的开始和结束时间?
- python - 使用 boost::python 将数据缓冲区导入 C++
- c# - C#:在内存中加载大字典并从多个应用程序访问它
- xcode - Flutter / VS - 模拟器正在启动 - 错误
- android-studio - 使用手机时的 ETIMEOUT(连接超时)
- javascript - Linkedin JS SDK Share 响应成功但无法正常工作
- python - RDKit 如何从指纹更改为 Mol 或 Smiles