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

Problem adding if blocks inside a location using location_cfg_append/prepend #308

Closed
mezezo opened this issue May 5, 2014 · 2 comments
Closed

Comments

@mezezo
Copy link

mezezo commented May 5, 2014

Trying to add an if block inside an ginx::resource::location using location_cfg_append/prepend does not work as a trailing ; is appended to the closing }.

nginx::resource::location{ 'resources':
    location            => '/assets/',
    vhost               => $webserver_hostname,
    location_alias      => $versioned_assets,
    location_cfg_append => {
      'if'              => '($args ~ "debug=y") {
        rewrite .* /index.debug.html last;
      }',
      'try_files'       => '$uri /index.html',
      'expires'         => 'epoch',
    }
}

Looking at the generated conf file I can clearly see that a ; is after the closing } and nginx complains about it

Error: /Stage[main]/Nginx::Service/Service[nginx]: Could not restart Service[nginx]: Execution of '/sbin/service nginx restart' returned 1: nginx: [emerg] unexpected ";" in /etc/nginx/sites-enabled...

What is the right way to add an if block inside a location element?

@mezezo mezezo changed the title Issu adding if blocks inside a location Problem adding if blocks inside a location using location_cfg_append/prepend May 5, 2014
@3flex
Copy link
Contributor

3flex commented Jul 21, 2014

Use location_custom_cfg_append instead. It doesn't add the trailing ;.

If you do replace your location_cfg_append with location_custom_cfg_append you'll have to manually add the trailing ; to every directive (i.e. your try_files, expires)

@3flex
Copy link
Contributor

3flex commented Jul 21, 2014

There's also raw_append which lets you add an array of lines you want added to the config verbatim.

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

2 participants