Using Puppet with complex Nginx VirtualHosts

andrewvnice asked:

I’m trying to use Puppet and a Nginx plugin to manage a virtual host config file. I have everything working, but now that I need to add some rewrite rules I’m running into issues.

I know I can use syntax like the line below to add a simple rule…

location_cfg_append => { 'rewrite' => '^ https://$server_name$request_uri? permanent' },

but I’m totally not getting how to use a slightly more complex set up such as

if (!-e $request_filename){
  rewrite ^(.*)$ /index.php break;
}

My answer:


Your example should not be a rewrite at all. It should be the last entry in the try_files directive. For instance:

server {
    #.....stuff.....
    try_files $uri $uri/ /index.php;

Your puppet module seems to support a try_files parameter in nginx::resource::vhost.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.