Putting if else in nginx Vhost configuration with Puppet Nginx jfryman module
I had the same problem with v0.0.9 of jfryman-nginx.
In the latest source templates on github, it looks like the ;
is not supposed to be added if you use location_custom_cfg_{pre,ap}pend
.
But in v0.0.9, the latest bundled puppet forge release, the template adds the ;
after even if the line only has a }
causing nginx
to fail.
Solutions:
Use the
location_**custom**_cfg_{pre,ap}pend
options-
Either A or B:
A. Edit out the
;
in the templatesB. Pull the latest version of the source from github:
sudo rm -rf /etc/puppet/modules/nginx && cd /etc/puppet/modules && sudo git clone https://github.com/jfryman/puppet-nginx nginx
Example
nginx::resource::location { 'sub.dom.com_root':
ensure => present,
vhost => 'sub.dom.com',
location => '~ \.php$',
fastcgi => 'unix:/var/run/php5-fpm.sock',
www_root => '/var/www/sub.dom.com',
location_custom_cfg_append => {
'if (-f $request_filename)' => '{ break; }',
'if (-d $request_filename)' => '{ break; }',
'if ($request_filename !~ (js|css|jpg|png|gif|robots\.txt|index\.php.*) )' => '{ rewrite ^/(.*) /index.php?$1 last; }',
},
}
Comments
-
maths almost 2 years
I want to automate the nginx vhost configuration for a website which have some if conditional statements. I was trying to do it with the jfryman-nginx puppet forge module but I am not able to configure the file. The configuration I want is given below:
server { listen 8080; server_name abcqwe.com; root /data/vvv/abcqwe.com; index index.php index.html index.htm; access_log /data/vvv/abcqwe.com/logs/access.log; error_log /data/vvv/abcqwe.com/logs/error.log; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html #try_files $uri $uri/ /index.html; if (!-f $request_filename){ set $rule_0 1$rule_0; } try_files $uri $uri/ /index.html; }
So how do i put this if condition inside my vhost configuration:
if (!-f $request_filename){ set $rule_4 1$rule_4; }
Is it possible to do it though? I have tried with
location_cfg_prepend
but that didn't help..