Skip to content

Commit

Permalink
issue voxpupuli#348: vhost to server
Browse files Browse the repository at this point in the history
Based on the discussion we had, I've renamed all instances of 'vhost' to
'server'.

The main reason for this is that NginX does not uphold the concept of
vHost: https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/

Stating:

    "Note: “VirtualHost” is an Apache term. NGINX does not have Virtual
    hosts, it has “Server Blocks” that use the server_name and listen
    directives to bind to tcp sockets."

Besides, the extended use of the concept causes confusion and
misunderstanding when it comes to NginX.

I still need to work on two more requests.
  • Loading branch information
renich committed Oct 17, 2016
1 parent 3e9ea24 commit df59538
Show file tree
Hide file tree
Showing 24 changed files with 281 additions and 281 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class { 'nginx': }
### A simple reverse proxy

```puppet
nginx::resource::vhost { 'kibana.myhost.com':
nginx::resource::server { 'kibana.myhost.com':
listen_port => 80,
proxy => 'http://localhost:5601',
}
Expand All @@ -45,7 +45,7 @@ nginx::resource::vhost { 'kibana.myhost.com':
### A virtual host with static content

```puppet
nginx::resource::vhost { 'www.puppetlabs.com':
nginx::resource::server { 'www.puppetlabs.com':
www_root => '/var/www/www.puppetlabs.com',
}
```
Expand All @@ -61,7 +61,7 @@ nginx::resource::upstream { 'puppet_rack_app':
],
}
nginx::resource::vhost { 'rack.puppetlabs.com':
nginx::resource::server { 'rack.puppetlabs.com':
proxy => 'http://puppet_rack_app',
}
```
Expand All @@ -88,26 +88,26 @@ nginx::resource::mailhost { 'domain1.example':

## SSL configuration

By default, creating a vhost resource will only create a HTTP vhost. To also create a HTTPS (SSL-enabled) vhost, set `ssl => true` on the vhost. You will have a HTTP server listening on `listen_port` (port `80` by default) and a HTTPS server listening on `ssl_port` (port `443` by default). Both vhosts will have the same `server_name` and a similar configuration.
By default, creating a server resource will only create a HTTP server. To also create a HTTPS (SSL-enabled) server, set `ssl => true` on the server. You will have a HTTP server listening on `listen_port` (port `80` by default) and a HTTPS server listening on `ssl_port` (port `443` by default). Both servers will have the same `server_name` and a similar configuration.

To create only a HTTPS vhost, set `ssl => true` and also set `listen_port` to the same value as `ssl_port`. Setting these to the same value disables the HTTP vhost. The resulting vhost will be listening on `ssl_port`.
To create only a HTTPS server, set `ssl => true` and also set `listen_port` to the same value as `ssl_port`. Setting these to the same value disables the HTTP server. The resulting server will be listening on `ssl_port`.

### Locations

Locations require specific settings depending on whether they should be included in the HTTP, HTTPS or both vhosts.
Locations require specific settings depending on whether they should be included in the HTTP, HTTPS or both servers.

#### HTTP only vhost (default)
If you only have a HTTP vhost (i.e. `ssl => false` on the vhost) make sure you don't set `ssl => true` on any location you associate with the vhost.
#### HTTP only server (default)
If you only have a HTTP server (i.e. `ssl => false` on the server) make sure you don't set `ssl => true` on any location you associate with the server.

#### HTTP and HTTPS vhost
If you set `ssl => true` and also set `listen_port` and `ssl_port` to different values on the vhost you will need to be specific with the location settings since you will have a HTTP vhost listening on `listen_port` and a HTTPS vhost listening on `ssl_port`:
#### HTTP and HTTPS server
If you set `ssl => true` and also set `listen_port` and `ssl_port` to different values on the server you will need to be specific with the location settings since you will have a HTTP server listening on `listen_port` and a HTTPS server listening on `ssl_port`:

* To add a location to only the HTTP server, set `ssl => false` on the location (this is the default).
* To add a location to both the HTTP and HTTPS server, set `ssl => true` on the location, and ensure `ssl_only => false` (which is the default value for `ssl_only`).
* To add a location only to the HTTPS server, set both `ssl => true` and `ssl_only => true` on the location.

#### HTTPS only vhost
If you have set `ssl => true` and also set `listen_port` and `ssl_port` to the same value on the vhost, you will have a single HTTPS vhost listening on `ssl_port`. To add a location to this vhost set `ssl => true` and `ssl_only => true` on the location.
#### HTTPS only server
If you have set `ssl => true` and also set `listen_port` and `ssl_port` to the same value on the server, you will have a single HTTPS server listening on `ssl_port`. To add a location to this server set `ssl => true` and `ssl_only => true` on the location.

## Hiera Support

Expand All @@ -121,19 +121,19 @@ nginx::nginx_upstreams:
- localhost:3000
- localhost:3001
- localhost:3002
nginx::nginx_vhosts:
nginx::nginx_servers:
'www.puppetlabs.com':
www_root: '/var/www/www.puppetlabs.com'
'rack.puppetlabs.com':
proxy: 'http://puppet_rack_app'
nginx::nginx_locations:
'static':
location: '~ "^/static/[0-9a-fA-F]{8}\/(.*)$"'
vhost: www.puppetlabs.com
server: www.puppetlabs.com
www_root: /var/www/html
'userContent':
location: /userContent
vhost: www.puppetlabs.com
server: www.puppetlabs.com
www_root: /var/www/html
nginx::nginx_mailhosts:
'smtp':
Expand Down Expand Up @@ -174,9 +174,9 @@ Package source `passenger` will add [Phusion Passenger repository](https://oss-b
For each virtual host you should specify which ruby should be used.

```puppet
nginx::resource::vhost { 'www.puppetlabs.com':
nginx::resource::server { 'www.puppetlabs.com':
www_root => '/var/www/www.puppetlabs.com',
vhost_cfg_append => {
server_cfg_append => {
'passenger_enabled' => 'on',
'passenger_ruby' => '/usr/bin/ruby',
}
Expand All @@ -188,15 +188,15 @@ nginx::resource::vhost { 'www.puppetlabs.com':
Virtual host config for serving puppet master:

```puppet
nginx::resource::vhost { 'puppet':
nginx::resource::server { 'puppet':
ensure => present,
server_name => ['puppet'],
listen_port => 8140,
ssl => true,
ssl_cert => '/var/lib/puppet/ssl/certs/example.com.pem',
ssl_key => '/var/lib/puppet/ssl/private_keys/example.com.pem',
ssl_port => 8140,
vhost_cfg_append => {
server_cfg_append => {
'passenger_enabled' => 'on',
'passenger_ruby' => '/usr/bin/ruby',
'ssl_crl' => '/var/lib/puppet/ssl/ca/ca_crl.pem',
Expand All @@ -215,7 +215,7 @@ nginx::resource::vhost { 'puppet':
}
```

### Example puppet class calling nginx::vhost with HTTPS FastCGI and redirection of HTTP
### Example puppet class calling nginx::server with HTTPS FastCGI and redirection of HTTP

```puppet
Expand All @@ -228,7 +228,7 @@ define web::nginx_ssl_with_redirect (
$www_root = "${full_web_path}/${name}/",
$location_cfg_append = undef,
) {
nginx::resource::vhost { "${name}.${::domain}":
nginx::resource::server { "${name}.${::domain}":
ensure => present,
www_root => "${full_web_path}/${name}/",
location_cfg_append => { 'rewrite' => '^ https://$server_name$request_uri? permanent' },
Expand All @@ -240,7 +240,7 @@ define web::nginx_ssl_with_redirect (
$tmp_www_root = $www_root
}
nginx::resource::vhost { "${name}.${::domain} ${name}":
nginx::resource::server { "${name}.${::domain} ${name}":
ensure => present,
listen_port => 443,
www_root => $tmp_www_root,
Expand All @@ -258,7 +258,7 @@ define web::nginx_ssl_with_redirect (
ensure => present,
ssl => true,
ssl_only => true,
vhost => "${name}.${::domain} ${name}",
server => "${name}.${::domain} ${name}",
www_root => "${full_web_path}/${name}/",
location => '~ \.php$',
index_files => ['index.php', 'index.html', 'index.htm'],
Expand Down
4 changes: 2 additions & 2 deletions docs/hiera.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Assume you have the following code block:
class { 'nginx' :
manage_repo => false,
confd_purge => true,
vhost_purge => true,
server_purge => true,
}
```

Expand All @@ -44,7 +44,7 @@ Anchor['nginx::begin']
->
class { 'nginx::config' :
confd_purge => true,
vhost_purge => true,
server_purge => true,
}

class { 'nginx' :
Expand Down
10 changes: 5 additions & 5 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The choices here are `nginx-stable` (the current 'production' level release), `n
Calling the `nginx` class from your manifest simply installs the NGINX software and puts some basic configuration in place. In this state, NGINX will not serve web pages or proxy to other services - for that, we need to define a *server*. In NGINX terminology, a *server* is how we define our services (such as websites) with a name. (If you are used to configuring Apache, a server is identical to an Apache *virtual host*.) A simple virtual host that serves static web pages can be defined with a server name and a *web root*, or the directory where our HTML pages are located.

```
nginx::resource::vhost{'www.myhost.com':
nginx::resource::server{'www.myhost.com':
www_root => '/opt/html/',
}
```
Expand All @@ -35,7 +35,7 @@ Setting up a simple static webserver is straightforward, but is usually not the
```
nginx::resource::location{'/blog':
proxy => 'http://192.168.99.1/' ,
vhost => 'www.myhost.com'
server => 'www.myhost.com'
}
```
This will proxy any requests made to `http://www.myhost.com/blog` to the URL `http://192.168.99.1/`. Pay special attention to the use of `/` at the end of the URL we are proxying to - that will allow your query parameters or subfolder structure on your secondary webserver to remain intact.
Expand All @@ -56,7 +56,7 @@ We can expand on these simple proxies by defining *upstream* resources for our w
```
nginx::resource::location{'/blog':
proxy => 'http://upstream_app/' ,
vhost => 'www.myhost.com'
server => 'www.myhost.com'
}
```
Now `/blog` will proxy requests to services defined in our `upstream_app` resource.
Expand All @@ -78,13 +78,13 @@ Combining our configurations above into a single manifest, our code block looks
],
}
nginx::resource::vhost{'www.myhost.com':
nginx::resource::server{'www.myhost.com':
www_root => '/opt/html/',
}
nginx::resource::location{'/proxy':
proxy => 'http://upstream_app/' ,
vhost => 'www.myhost.com',
server => 'www.myhost.com',
}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/location_alias.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
ensure => present,
location => '/some/url',
location_alias => '/new/url/',
vhost => 'www.test.com',
server => 'www.test.com',
}
2 changes: 1 addition & 1 deletion examples/location_params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
::nginx::resource::location { 'www.test.com-params':
ensure => present,
location => '/some/url',
vhost => 'www.test.com',
server => 'www.test.com',
fastcgi_param => {
'APP_ENV' => 'production',
'APP_VERSION' => '0.1.10',
Expand Down
4 changes: 2 additions & 2 deletions examples/vhost.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
include ::nginx

::nginx::resource::vhost { 'test.local test':
::nginx::resource::server { 'test.local test':
ensure => present,
ipv6_enable => true,
proxy => 'http://proxypass',
}

::nginx::resource::vhost { 'test.local:8080':
::nginx::resource::server { 'test.local:8080':
ensure => present,
listen_port => 8080,
server_name => ['test.local test'],
Expand Down
8 changes: 4 additions & 4 deletions examples/vhost_ssl.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include ::nginx

::nginx::resource::vhost { 'test3.local test3':
::nginx::resource::server { 'test3.local test3':
ensure => present,
www_root => '/var/www/nginx-default',
ssl => true,
Expand All @@ -9,7 +9,7 @@
ssl_key => 'puppet:///modules/sslkey/whildcard_mydomain.key',
}

::nginx::resource::vhost { 'test2.local test2':
::nginx::resource::server { 'test2.local test2':
ensure => present,
www_root => '/var/www/nginx-default',
ssl => true,
Expand All @@ -21,12 +21,12 @@
ensure => present,
www_root => '/var/www/bob',
location => '/bob',
vhost => 'test2.local test2',
server => 'test2.local test2',
}

::nginx::resource::location { 'test3.local-bob':
ensure => present,
www_root => '/var/www/bob',
location => '/bob',
vhost => 'test3.local test3',
server => 'test3.local test3',
}
12 changes: 6 additions & 6 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
$sites_available_mode = $::nginx::params::sites_available_mode,
$super_user = $::nginx::params::super_user,
$temp_dir = $::nginx::params::temp_dir,
$vhost_purge = false,
$server_purge = false,

# Primary Templates
$conf_template = 'nginx/conf.d/nginx.conf.erb',
Expand Down Expand Up @@ -143,7 +143,7 @@
}
validate_bool($confd_only)
validate_bool($confd_purge)
validate_bool($vhost_purge)
validate_bool($server_purge)
if ( $proxy_cache_path != false) {
if ( is_string($proxy_cache_path) or is_hash($proxy_cache_path)) {}
else {
Expand Down Expand Up @@ -235,10 +235,10 @@
ensure => directory,
}
if $confd_purge {
# Err on the side of caution - make sure *both* $vhost_purge and
# Err on the side of caution - make sure *both* $server_purge and
# $confd_purge are set if $confd_only is set, before purging files
# ${conf_dir}/conf.d
if (($confd_only and $vhost_purge) or !$confd_only) {
if (($confd_only and $server_purge) or !$confd_only) {
File["${conf_dir}/conf.d"] {
purge => true,
recurse => true,
Expand Down Expand Up @@ -290,7 +290,7 @@
file { "${conf_dir}/sites-enabled":
ensure => directory,
}
if $vhost_purge {
if $server_purge {
File["${conf_dir}/sites-available"] {
purge => true,
recurse => true,
Expand All @@ -309,7 +309,7 @@
file { "${conf_dir}/streams-available":
ensure => directory,
}
if $vhost_purge == true {
if $server_purge == true {
File["${conf_dir}/streams-enabled"] {
purge => true,
recurse => true,
Expand Down
12 changes: 6 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
$sites_available_mode = undef,
$super_user = undef,
$temp_dir = undef,
$vhost_purge = undef,
$server_purge = undef,

# Primary Templates
$conf_template = undef,
Expand Down Expand Up @@ -127,8 +127,8 @@
$nginx_mailhosts = {},
$nginx_streamhosts = {},
$nginx_upstreams = {},
$nginx_vhosts = {},
$nginx_vhosts_defaults = {},
$nginx_servers = {},
$nginx_servers_defaults = {},
### END Hiera Lookups ###
) inherits ::nginx::params {

Expand Down Expand Up @@ -204,7 +204,7 @@
$temp_dir or
$types_hash_bucket_size or
$types_hash_max_size or
$vhost_purge or
$server_purge or
$worker_connections or
$worker_processes or
$worker_rlimit_nofile or
Expand Down Expand Up @@ -291,7 +291,7 @@
temp_dir => $temp_dir,
types_hash_bucket_size => $types_hash_bucket_size,
types_hash_max_size => $types_hash_max_size,
vhost_purge => $vhost_purge,
server_purge => $server_purge,
worker_connections => $worker_connections,
worker_processes => $worker_processes,
worker_rlimit_nofile => $worker_rlimit_nofile,
Expand All @@ -309,7 +309,7 @@
Class['::nginx::package'] -> Class['::nginx::config'] ~> Class['::nginx::service']

create_resources('nginx::resource::upstream', $nginx_upstreams)
create_resources('nginx::resource::vhost', $nginx_vhosts, $nginx_vhosts_defaults)
create_resources('nginx::resource::server', $nginx_servers, $nginx_servers_defaults)
create_resources('nginx::resource::location', $nginx_locations)
create_resources('nginx::resource::mailhost', $nginx_mailhosts)
create_resources('nginx::resource::streamhost', $nginx_streamhosts)
Expand Down
Loading

0 comments on commit df59538

Please sign in to comment.