Class: Nginx::RailsLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/shared_infrastructure/nginx/location.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain_name) ⇒ RailsLocation

Returns a new instance of RailsLocation.



74
75
76
# File 'lib/shared_infrastructure/nginx/location.rb', line 74

def initialize(domain_name)
  @domain_name = domain_name
end

Instance Method Details

#to_s(level = 0) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/shared_infrastructure/nginx/location.rb', line 78

def to_s(level = 0)
  Lines.new("location @#{domain_name} {",
    "  # A Rails app should force \"SSL\" so that it generates redirects to HTTPS,",
    "  # among other things.",
    "  # However, you want Nginx to handle the workload of TLS.",
    "  # The trick to proxying to a Rails app, therefore, is to proxy pass to HTTP,",
    "  # but set the header to HTTPS",
    "  # Next two lines.",
    "  proxy_pass http://#{domain_name};",
    "  proxy_set_header X-Forwarded-Proto $scheme; # $scheme says http or https",
    "  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;",
    "  proxy_set_header Host $http_host;",
    "  proxy_redirect off;",
    "}").format(level)
end