如何将两个相似的位置块合并为一个?

如何将两个相似的位置块合并为一个?

以下位置块看起来像是可以缓解的冗余 - 如何缓解?

location / {
    proxy_pass http://127.0.0.1:8443;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

location ~* \.io {
    proxy_pass         http://127.0.0.1:8443;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection 'upgrade';
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
}

答案1

将通用配置存储在单独的.conf 文件中:

/etc/nginx/config/proxy.conf:

proxy_pass http://127.0.0.1:8443;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;

位置块包括常见的proxy.conf-:

location / {
   include /etc/nginx/conf/proxy.conf;
}

location ~* \.io {
   include /etc/nginx/conf/proxy.conf;
}

相关内容