Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Forgotten changes.

  • Loading branch information...
commit af8364d07ce29245f64748a573109b1e89cdd382 1 parent 12bcb42
@pwnall authored
Showing with 20 additions and 18 deletions.
  1. +2 −0  CHANGELOG
  2. +18 −18 lib/rails_pwnerer/app/nginx_config.rb
View
2  CHANGELOG
@@ -1,3 +1,5 @@
+v0.6.108. Re-release with X-Forwarded-For for real.
+
v0.6.107. Added X-Forwarded-For header to nginx config.
v0.6.106. Better check for thin in application Gemfile.
View
36 lib/rails_pwnerer/app/nginx_config.rb
@@ -2,24 +2,24 @@
class RailsPwnerer::App::NginxConfig
include RailsPwnerer::Base
-
+
# writes the nginx configuration for this server
def config_nginx(app_name, instance_name)
app_config = RailsPwnerer::Config[app_name, instance_name]
first_port = app_config[:port0]
-
+
# Can be specified as comma-separated string or array.
if app_config[:dns_name].respond_to? :to_str
dns_names = app_config[:dns_name].split(',')
else
dns_names = app_config[:dns_name]
end
-
+
default_app_port = app_config[:ssl_key] ? 443 : 80
app_port = app_config[:port] || default_app_port
-
+
nginx_config = File.join(RailsPwnerer::Config.path_to(:nginx_configs),
- app_name + '.' + instance_name)
+ app_name + '.' + instance_name)
File.open(nginx_config, 'w') do |f|
# link to the frontends
f << " upstream #{app_name}_#{instance_name} {\n"
@@ -27,7 +27,7 @@ def config_nginx(app_name, instance_name)
f << " server 127.0.0.1:#{first_port + instance};\n"
end
f << " }\n\n"
-
+
# server configuration -- big and ugly
f << <<NGINX_CONFIG
server {
@@ -44,7 +44,7 @@ def config_nginx(app_name, instance_name)
expires max;
add_header Cache-Control public;
break;
- }
+ }
error_page 404 /404.html;
error_page 500 502 503 504 /500.html;
location / {
@@ -64,7 +64,7 @@ def config_nginx(app_name, instance_name)
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- #{app_config[:ssl_key] ? 'proxy_set_header X-Forwarded-Proto https;' : ''}
+ proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_redirect off;
proxy_connect_timeout 2;
@@ -74,38 +74,38 @@ def config_nginx(app_name, instance_name)
break;
}
}
- }
+ }
NGINX_CONFIG
- end
+ end
end
-
+
def remove_nginx_config(app_name, instance_name)
- nginx_config = File.join(RailsPwnerer::Config.path_to(:nginx_configs), app_name + '.' + instance_name)
- File.delete nginx_config if File.exists? nginx_config
+ nginx_config = File.join(RailsPwnerer::Config.path_to(:nginx_configs), app_name + '.' + instance_name)
+ File.delete nginx_config if File.exists? nginx_config
end
-
+
# removes the default configuration stub (so nginx doesn't stumble upon it)
def remove_nginx_stub
stub_file = File.join(RailsPwnerer::Config.path_to(:nginx_configs), 'default')
File.delete stub_file if File.exists?(stub_file)
end
-
+
def setup(app_name, instance_name)
config_nginx app_name, instance_name
remove_nginx_stub
control_boot_script('nginx', :reload)
end
-
+
def update(app_name, instance_name)
config_nginx app_name, instance_name
control_boot_script('nginx', :reload)
end
-
+
def remove(app_name, instance_name)
remove_nginx_config app_name, instance_name
control_boot_script('nginx', :reload)
end
-
+
def control_all(action)
case action
when :start
Please sign in to comment.
Something went wrong with that request. Please try again.