2

I have an nginx location block that should be delegated to uwsgi backend and provide http --> https redirection, so it goes as follows:

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 ...
    }

What I want, is for a specific endpoint not to provide https redirection, so I am forced to do the following:

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 ...
    }

}

Is there a way nginx allows to avoid the above duplication of uwsgi parameters definition?

pkaramol
  • 16,451
  • 43
  • 149
  • 324
  • All of those parameters can be inherited from the `server` block level. See [this link](http://nginx.org/en/docs/http/ngx_http_uwsgi_module.html). – Richard Smith Mar 07 '18 at 13:36

1 Answers1

3

2 options:

  1. Move the params that have server context and must affect all locations our of the location block to the server block
  2. Use include to share common code to avoid copy & paste

Includes another file, or files matching the specified mask, into configuration. Included files should consist of syntactically correct directives and blocks.

Oleg Kuralenko
  • 11,003
  • 1
  • 30
  • 40