Cookbooks
nginx
documentation
Nginx Site

nginx_site

Back to resource list

Actions

  • :create - Create an nginx site configuration file
  • :delete - Delete an nginx site configuration file
  • :enable - Enable a pre-existing configuration file
  • :disable - Disable a pre-existing configuration file

Properties

NameTypeDefaultDescription
conf_dirString/etc/nginx/conf.http.dDirectory to create configuration file in
cookbookStringnginxCookbook to source configuration file template from
templateStringsite-template.erbTemplate to use to generate the configuration file
ownerStringrootNginx configuration file/folder owner.
groupStringrootNginx configuration file/folder group.
modeString0640Nginx configuration file mode.
folder_modeString0750Nginx configuration folder mode.
variablesHash{}Additional variables to include in site template
template_helpersString, ArraynilAdditional helper modules to include in the site template

Usage

Example

Using the default template

nginx_site 'test_site' do
  mode '0644'
 
  variables(
    'server' => {
      'listen' => [ '*:80' ],
      'server_name' => [ 'test_site' ],
      'access_log' => '/var/log/nginx/test_site.access.log',
      'locations' => {
        '/' => {
          'root' => '/var/www/nginx-default',
          'index' => 'index.html index.htm',
        },
      },
    }
  )
 
  action :create
  notifies :reload, 'nginx_service[nginx]', :delayed
end

Overriden template and disabled

nginx_site 'test_site_disabled' do
  template 'default-site.erb'
 
  variables(
    'port': 80,
    'server_name': 'test_site',
    'default_root': '/var/www/nginx-default',
    'nginx_log_dir': '/var/log/nginx'
  )
  action [:create, :disable]
  notifies :reload, 'nginx_service[nginx]', :delayed
end