1
votes

I setup my vagrant box via a pre-configured https://puphpet.com/ package with PHP 5.4 and Nginx.

After provisioning, I always have to change the vhost_autogen.conf by myself - I guess that cannot be the idea behind vagrant and puppet :-) How can I:

  • remove the vhost_autogen.conf automatically and replace it with another one

OR

  • add the settings below as puppet configuration?

This is the required vhost setting:

server {

listen *:80;

server_name example.dev www.example.dev;

root /var/www/example.com;

index index.php;

access_log /var/log/nginx/example.com.de.access.log;

error_log /var/log/nginx/example.com.error.log;

if ($host ~* www.(.*)) { set $host_without_www $1; rewrite ^(.*)$ $scheme://$host_without_www$1 permanent; #1 #rewrite ^ $scheme://$host_without_www$1request_uri permanent; #2 }

# Rewrite for minify rewrite ^/min/([a-z]=.*) /min/index.php?$1 last;

# canonicalize codeigniter url end points

if ($request_uri ~* ^(/start(/index)?|/index(.php)?)/?$) { rewrite ^(.*)$ / permanent; }

# removes trailing "index" from all controllers if ($request_uri ~* index/?$) { rewrite ^/(.*)/index/?$ /$1 permanent; }

# removes trailing slashes (prevents SEO duplicate content issues) if (!-d $request_filename) { rewrite ^/(.+)/$ /$1 permanent; }

# removes access to "system" folder, also allows a "System.php" controller if ($request_uri ~* ^/system) { rewrite ^/(.*)$ /index.php?/$1 last; break; }

# unless the request is for a valid file (image, js, css, etc.), send to bootstrap if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?/$1 last; break; }

# catch all error_page 404 /index.php;

location / { root /var/www/example.com; rewrite ^/min/([a-z]=.*) /min/index.php?$1 last; }

location = /robots.txt { access_log off; log_not_found off; } location = /favicon.ico { access_log off; log_not_found off; } location ~ /. { access_log off; log_not_found off; deny all; } location ~ ~$ { access_log off; log_not_found off; deny all; }

location ~ .php$ { root /var/www/example.com; try_files $uri $uri/ /index.php?$args ; index index.html index.htm index.php; fastcgi_index index.php; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param APP_ENV dev;

   fastcgi_pass unix:/var/run/php5-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   include fastcgi_params;

} }

1

1 Answers

0
votes

In puppet/manifest.pp, search for create_resources(nginx_vhost, $nginx_values['vhosts']), replace it with the following:

  file { "/etc/nginx/sites-enabled/my-site.conf":
  source => '/full/path/to/conf/file',
  owner  => 'root',
  group  => 'root',
  mode   => '0644'
  }