├── templates ├── vhost.conf.erb └── vhost.php.conf.erb ├── manifests ├── init.pp └── vhost.pp └── README.md /templates/vhost.conf.erb: -------------------------------------------------------------------------------- 1 | server { 2 | server_name <%= server_name %>; 3 | root <%= root %>; 4 | 5 | <% if server_name === '_' %> 6 | server_name_in_redirect off; 7 | <% end %> 8 | 9 | index <%= index %>; 10 | } -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | class nginx ( 2 | $ensure = 'present', 3 | $default_vhost = false, 4 | ) { 5 | 6 | $running = $ensure ? { 7 | absent => 'stopped', 8 | default => 'running', 9 | } 10 | 11 | $default_vhost_ensure = $default_vhost ? { 12 | true => 'link', 13 | default => 'absent', 14 | } 15 | 16 | package { 'nginx': 17 | ensure => $ensure, 18 | } 19 | 20 | service { 'nginx': 21 | ensure => $running, 22 | require => Package['nginx'], 23 | } 24 | 25 | file { '/etc/nginx/sites-enabled/default': 26 | ensure => $default_vhost_ensure, 27 | target => '/etc/nginx/sites-available/default', 28 | notify => Service['nginx'], 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /templates/vhost.php.conf.erb: -------------------------------------------------------------------------------- 1 | server 2 | { 3 | server_name <%= server_name %>; 4 | root <%= root %>; 5 | 6 | client_max_body_size 100M; 7 | fastcgi_read_timeout 1800; 8 | 9 | index <%= index %>; 10 | 11 | location / 12 | { 13 | try_files $uri $uri/ /<%= index %>; 14 | } 15 | 16 | location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 17 | expires max; 18 | log_not_found off; 19 | access_log off; 20 | } 21 | 22 | location ~ \.php$ 23 | { 24 | try_files $uri =404; 25 | 26 | include fastcgi_params; 27 | fastcgi_index <%= index %>; 28 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 29 | fastcgi_pass <%= fastcgi_socket %>; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /manifests/vhost.pp: -------------------------------------------------------------------------------- 1 | define nginx::vhost ( 2 | $ensure = 'present', 3 | $root = '/var/www', 4 | $priority = '50', 5 | $file = $name, 6 | $server_name = $name, 7 | $index = 'index.html', 8 | $fastcgi_socket = '127.0.0.1:9000', 9 | $template = 'nginx/vhost.conf.erb', 10 | ) { 11 | include nginx 12 | 13 | $link_ensure = $ensure ? { 14 | 'present' => 'link', 15 | default => 'absent', 16 | } 17 | 18 | $file_ensure = $ensure ? { 19 | 'present' => 'file', 20 | default => 'absent', 21 | } 22 | 23 | file { "/etc/nginx/sites-available/${priority}-${file}.conf": 24 | ensure => $file_ensure, 25 | content => template($template), 26 | require => File["/etc/nginx/sites-enabled/${priority}-${file}.conf"], 27 | notify => Service['nginx'], 28 | } 29 | 30 | file { "/etc/nginx/sites-enabled/${priority}-${file}.conf": 31 | ensure => $link_ensure, 32 | target => "/etc/nginx/sites-available/${priority}-${file}.conf", 33 | require => Package['nginx'], 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This puppet module aims to be lightweight and help you get an nginx virtual host up and running quickly. It was developed with Vagrant in mind so that I could get a web environment up and running in as few lines as possible. 2 | 3 | ## How to use 4 | 5 | Clone this into your modules directory. Then in your manifests file, add the following: 6 | 7 | nginx::vhost { 'your.domain.com': 8 | root => '/path/to/docroot', 9 | } 10 | 11 | That's it! If you was expecting more, this module probably isn't for you. Though, there are a few options: 12 | 13 | nginx::vhost { 'my site': 14 | root => '/var/www', 15 | ensure => present, 16 | priority => '3', 17 | file => 'my-site', 18 | server_name => 'my.site.com', 19 | template => 'myconfig/mysite.conf.erb', 20 | } 21 | 22 | The `nginx` class can also be configured: 23 | 24 | class { 'nginx': 25 | ensure => present, 26 | default_vhost => false, 27 | } 28 | 29 | ## PHP-fpm 30 | 31 | If you're looking for php-fpm functionallity too, check out my other module, [phpfpm](https://github.com/davidwinter/puppet-phpfpm), which includes a resource for adding virtual hosts to nginx. 32 | 33 | ## Contribute 34 | 35 | Please feel free to submit pull requests for any other basic functionallity you think this module should include. 36 | --------------------------------------------------------------------------------