add nginx

This commit is contained in:
John Bintz 2012-01-30 22:14:25 -05:00
parent 74e3fd9db1
commit b2c4e2808f
6 changed files with 163 additions and 0 deletions

View File

@ -13,7 +13,10 @@ end
Capistrano::Configuration.instance.load do Capistrano::Configuration.instance.load do
_cset(:puppet_dir) { '/tmp/puppet' } _cset(:puppet_dir) { '/tmp/puppet' }
_cset(:additional_puppet_bin_path) { nil } _cset(:additional_puppet_bin_path) { nil }
_cset(:base_dir) { '/usr/local' } _cset(:base_dir) { '/usr/local' }
_cset(:src_dir) { '/usr/src' }
_cset(:rename_server) { true } _cset(:rename_server) { true }
_cset(:use_sudo) { true } _cset(:use_sudo) { true }
_cset(:additional_modules) { [] } _cset(:additional_modules) { [] }
@ -24,6 +27,16 @@ Capistrano::Configuration.instance.load do
use_sudo ? "sudo -p 'sudo password: '" : "" use_sudo ? "sudo -p 'sudo password: '" : ""
end end
desc "Clear specified source directories"
task :clear_source do
run "cd #{src_dir} && #{sudo} rm -Rf #{sources}"
end
desc "Clear specified apps"
task :clear_apps do
run "cd #{base_dir} && #{sudo} rm -Rf #{apps}"
end
desc "Apply the configuration" desc "Apply the configuration"
task :apply do task :apply do
top.copy top.copy

View File

@ -0,0 +1,70 @@
class nginx($version) {
gem { 'passenger':
version => $version,
path => "${ruby::with_ruby_path}",
require => Build_and_install['ruby'],
ensure => present
}
$install_path = install_path($name, $version)
$symlink_path = symlink_path($name)
exec { 'install-passenger':
command => "passenger-install-nginx-module --auto --auto-download --prefix=${install_path}",
path => $ruby::with_ruby_path,
require => Gem['passenger'],
unless => "test -d ${install_path}",
timeout => 0,
logoutput => on_failure
}
$pid_file = pid_path($name)
$sbin_path = sbin_path($name)
$config_file = "${base::config_path}/nginx.conf"
$config_path = "${base::config_path}/nginx"
god_init { $name:
start => "${sbin_path}/nginx -c ${config_file}",
stop => "${sbin_path}/nginx -s stop -c ${config_file}",
pid_file => $pid_file,
ensure => present,
notify => Service['god'],
require => Exec['install-passenger']
}
file { [ '/var/log/nginx', $config_path ]:
ensure => directory,
before => God_init[$name]
}
file { [ "${config_path}/sites-available", "${config_path}/sites-enabled" ]:
ensure => directory,
require => File[$config_path],
}
file { $config_file:
content => template('nginx/nginx.conf'),
before => God_init[$name]
}
file { "${config_path}/fastcgi.conf":
content => template('nginx/fastcgi.conf'),
require => File[$config_file]
}
file { "${config_path}/fastcgi_params":
content => template('nginx/fastcgi_params'),
require => File[$config_file]
}
file { '/var/www': ensure => directory }
file { $symlink_path: ensure => $install_path }
file { "${base::install_path}/bin/new-site":
content => template('nginx/new-site'),
mode => 755
}
}

View File

@ -0,0 +1,8 @@
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_buffers 256 4k;
fastcgi_intercept_errors on;
## allow 4 hrs - pass timeout responsibility to upstrea
fastcgi_read_timeout 14400;
fastcgi_index index.php;

View File

@ -0,0 +1,22 @@
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

View File

@ -0,0 +1,12 @@
#!/bin/bash
if [ $UID -ne 0 ]; then
sudo $0 $@
exit
fi
cd /var/www
mkdir $1
chown :www-data $1
chmod 2775 $1

View File

@ -0,0 +1,38 @@
user www-data;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid <%= pid_file %>;
events {
worker_connections 1024;
}
http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml
application/xml application/xml+rss text/javascript;
include /etc/nginx/fastcgi.conf;
include /etc/nginx/sites-enabled/*;
}