我在 nginx.conf 文件中有两个不同的 server_name:
第一个为:
server_name ~^(?<subdomain>.+)\.nithinveer\.com$;
location /
{
proxy_pass http://192.168.6.190/Profiles/$subdomain/default.aspx$request_uri/;
access_log /var/log/nginx/true.log;
}
Run Code Online (Sandbox Code Playgroud)
另一个作为
server_name ~^(?<subdomain>.+)\.nithinveer\.com\.(?<extension>)$;
location /extension
{
proxy_pass http://192.168.6.190;
access_log /var/log/nginx/false.log;
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是我想同时使用基于 server_name 中的 server_name。如果 server_name 没有扩展名,它应该转到第一个位置。如果有分机,它应该转到第二个位置。
但是在运行 nginx 时,它并没有进入第二个 server_name
任何人都可以为此找到一些解决方案......?
我认为一个解决方案(可能是错误的)。
server_name ~^(?<subdomain>.+)\.nithinveer\.com\.(?<extension>.+)$;
if($<extension> == NULL)
{
location /
{
proxy_pass http://192.168.6.190/Profiles/$subdomain/default.aspx$request_uri/;
access_log /var/log/nginx/true.log;
}
}
else
{ location /
{
proxy_pass http://192.168.6.190;
access_log /var/log/nginx/false.log;
}
Run Code Online (Sandbox Code Playgroud)
但是带有 if 语句的语法会引发错误。