在nginx中的位置块之间共享指令

在nginx中的位置块之间共享指令,nginx,nginx-location,Nginx,Nginx Location,我有一个nginx位置块,应该委托给uwsgi后端,并提供http->https重定向,因此如下所示: location ~ ^/(api/v1) { if ($http_x_forwarded_proto != 'https') { rewrite ^ https://$host$request_uri? permanent; } access_log my-access.log; error_log my-error.log;

我有一个nginx位置块,应该委托给uwsgi后端,并提供http->https重定向,因此如下所示:

location  ~ ^/(api/v1) {
    if ($http_x_forwarded_proto != 'https') {
        rewrite ^ https://$host$request_uri? permanent;
    }
     access_log my-access.log;
     error_log my-error.log;
     include uwsgi_params;
     uwsgi_read_timeout 300;
     uwsgi_send_timeout 300;
     uwsgi_param ..;
     uwsgi_param ..;
     etc ...
    }
我想要的是,特定端点不提供https重定向,因此我被迫执行以下操作:

location  = /api/v1/my/more/specific/endpoint {
     access_log my-access.log;
     error_log my-error.log;
     include uwsgi_params;
     uwsgi_read_timeout 300;
     uwsgi_send_timeout 300;
     uwsgi_param ..;
     uwsgi_param ..;
     etc ...
    }
}

nginx是否有办法避免上述uwsgi参数定义的重复?

2选项:

将具有服务器上下文且必须影响位置块的所有位置的参数移动到服务器块 用于共享通用代码,以避免复制和粘贴 将另一个文件或与指定掩码匹配的文件包含到 配置包含的文件应包含语法正确的 指令和块


所有这些参数都可以从服务器块级别继承。看见