Skip to content

Nginx vhost with php support #416

@evancauwenberg

Description

@evancauwenberg

I have created a custom resource to add vhosts with direct php support.
The vhost is created and the custom location is added but if i try it it downloads all the files instead of processing them.

What am i missing?
https://github.com/jfryman/puppet-nginx/ is the module that i use.

The pp file:

$full_web_path = '/var/www'

define web::nginx_php_vhost (
  $backend_port         = 9000,
  $php                  = true,
  $proxy                = undef,
  $www_root             = "${full_web_path}/${name}/",
  $location_cfg_append  = undef,
) {
  nginx::resource::vhost { "${name}.${::domain} ${name}":
    ensure                => present,
    listen_port           => 80,
    www_root              => $www_root,
    owner                  => 'evancauwenberg',
    group                  => 'www-data',
    mode                   => '0755',
    access_log            => "/var/log/nginx/${name}_access.log",
    error_log             => "/var/log/nginx/${name}_error.log",
    location_cfg_append   => {
      try_files => '$uri $uri/ =404'
    },
    index_files           => [ 'index.php' ],
  }

  if $php {
    nginx::resource::location { "${name}_root":
      ensure          => present,
      vhost           => "${name}.${::domain} ${name}",
      www_root        => $www_root,
      location        => '~ \.php$',
      index_files     => ['index.php', 'index.html', 'index.htm'],
      proxy           => undef,
      fastcgi         => "127.0.0.1:${backend_port}",
      fastcgi_script  => undef,
      location_cfg_append => {
        fastcgi_split_path_info => '^(.+\.php)(/.+)$',
        fastcgi_index => 'index.php',
        fastcgi_connect_timeout => '3m',
        fastcgi_read_timeout    => '3m',
        fastcgi_send_timeout    => '3m'
      }
    }
  }
}


web::nginx_php_vhost { "evert.be":
  www_root => "/var/www/evert.be",
}

The created vhost:

server {
  listen                *:80;

  server_name           evert.be;

    index  index.php;

  access_log            /var/log/nginx/evert_access.log;
  error_log             /var/log/nginx/evert_error.log;

  location ~ \.php$ {

    root  /var/www/evert/evert.be;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;

    fastcgi_connect_timeout 3m;
    fastcgi_index index.php;
    fastcgi_read_timeout 3m;
    fastcgi_send_timeout 3m;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;;
  }
  location / {

    root  /var/www/evert/evert.be;
    try_files $uri $uri/ =404;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions