Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

location if statement #713

Closed
mnothic opened this issue Nov 3, 2015 · 4 comments
Closed

location if statement #713

mnothic opened this issue Nov 3, 2015 · 4 comments

Comments

@mnothic
Copy link

mnothic commented Nov 3, 2015

Hello I need put into a location an if statement like this
if $x-forwarded-proto = 'https' {
proxy_pass https://backend
}
else {
proxy_pass http://backend
}
some idea how I can achive this feature with this module?

@3flex 3flex changed the title ocation if statement location if statement Feb 8, 2016
@kotopes
Copy link

kotopes commented May 19, 2016

# in http section
map "$x-forwarded-proto" $loc_proto {
    default   "@loc_204";
     "https"  "@loc_https";
     "http"    "@loc_http";
}

# in server section
location / {
  try_files $uri $loc_proto;
}

location @loc_http {
   proxy_pass http://backend;
}

location @loc_https {
   proxy_pass https://backend;
}

location @loc_204 {
   return 204;
}

@wyardley
Copy link
Collaborator

@mnothic: did the proposed solution work for you? Can this be closed?

@rudybroersma
Copy link
Contributor

rudybroersma commented Oct 19, 2017

I am having a similiar issue. I have the following code:

 location_custom_cfg => {
                             'if' => '(!-e $request_filename) { rewrite / /index.php last; } ',
                             'set' => '$appname frontend',
                             'if' => '($request_uri ~* "shop-X-X") { set $appname admin; }',
                             'if' => '($request_uri ~* "admin") { set $appname admin; }',
                           },

This codes not work, because the plugin adds a ; after the statement, which nginx does not swallow.

I think a new option, something like 'custom_directives' would be usefull, where one can define configuration statements that are simply added without any additional parsing (eg. adding a ; at the end).

@wyardley
Copy link
Collaborator

@rudybroersma see
https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/location.pp#L54-L59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants