### ### HTTP-Config generated with magic_recipes_two at: <%= Time.now.strftime("%Y-%m-%d .. %H:%M .. %Z") %> ### upstream thin_<%= fetch(:application) %>_<%= fetch(:stage) %>_cluster { <% fetch(:app_instances).to_i.times do |i| %> server unix:/tmp/thin.<%= fetch(:application) %>.<%= fetch(:stage) %>.<%= i %>.sock max_fails=1 fail_timeout=15s; <% end %> } <%= magic_render("nginx/rails_cache_path") %> <%= magic_render("nginx/media_cache_path") %> # HTTP Server <% if fetch(:nginx_use_ssl) %> <% if fetch(:nginx_major_domain) %> server { listen 80<%= ' default_server' if fetch(:default_site) %>; server_name <%= nginx_domains_with_www.join(joiner) %> <%= nginx_major_domain %>; return 301 https://<%= nginx_major_domain %>$request_uri; } server { listen 80; server_name <%= nginx_domains.map{ |d| subdomain_regex(d) }.join(joiner) %> <%= subdomain_regex( nginx_major_domain ) %>; return 301 https://$sub.<%= nginx_major_domain %>$request_uri; } <% else %> server { listen 80; server_name <%= nginx_domains_with_www.join(joiner) %>; return 301 https://$host$request_uri; } server { listen 80; server_name <%= nginx_domains.map{ |d| subdomain_regex(d) }.join(joiner) %> return 301 https://$sub.$host$request_uri; } <% end %> <% end %> <% if fetch(:nginx_major_domain) %> <% if fetch(:nginx_use_ssl) %> # ssl-domain server { listen 443; server_name <%= nginx_domains.join(joiner) %>; ssl on; ssl_certificate <%= fetch(:nginx_other_ssl_cert) %>; ssl_certificate_key <%= fetch(:nginx_other_ssl_key) %>; return 301 https://<%= nginx_major_domain %>$request_uri; } # ssl-with-subdomain server { listen 443; server_name <%= nginx_domains.map{ |d| subdomain_regex(d) }.join(joiner) %>; ssl on; ssl_certificate <%= fetch(:nginx_other_ssl_cert) %>; ssl_certificate_key <%= fetch(:nginx_other_ssl_key) %>; return 301 https://$sub.<%= nginx_major_domain %>$request_uri; } <% else %> server { listen 80; server_name <%= nginx_domains_with_www.join(joiner) %>; return 301 http://<%= nginx_major_domain %>$request_uri; } server { listen 80; server_name <%= nginx_domains.map{ |d| subdomain_regex(d) }.join(joiner) %>; return 301 http://$sub.<%= nginx_major_domain %>$request_uri; } <% end %> <% end %> server { <% if fetch(:nginx_use_ssl) %> listen 443 ssl http2<%= ' default_server' if fetch(:default_site) %>; listen [::]:443 ssl http2<%= ' default_server' if fetch(:default_site) %>; ssl on; ssl_certificate <%= fetch(:nginx_ssl_cert) %>; ssl_certificate_key <%= fetch(:nginx_ssl_key) %>; <%= magic_render("nginx/diffie_hellman") %> <% else %> listen 80<%= ' default deferred' if fetch(:default_site) %>; listen [::]:80<%= ' default deferred' if fetch(:default_site) %>; <% end %> <% if fetch(:nginx_major_domain) %> server_name <%= "#{fetch(:nginx_domain_wildcard, false) ? "." : ""}#{fetch(:nginx_major_domain).gsub(/^\*?\./, "")}" %>; <% else %> server_name <%= nginx_domains_with_www.join(joiner) %>; <% end %> <%= magic_render("nginx/remove_www") %> root <%= current_path %>/public; access_log <%= fetch(:nginx_log_path) %>/nginx-access.log; error_log <%= fetch(:nginx_log_path) %>/nginx-error.log; error_page 404 /404.html; location /404.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:nginx_static_dir) %>; } error_page 500 502 503 504 /500.html; location /500.html { root <%= fetch (:deploy_to) %>/current/<%= fetch(:nginx_static_dir) %>; } client_max_body_size 4G; keepalive_timeout 10; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } <% if fetch(:allow_well_known) %> location ~ /.well-known { allow all; } <% end %> <%= magic_render("nginx/media_cache_server") %> try_files $uri/index.html $uri @thin_<%= fetch(:application) %>_<%= fetch(:stage) %>; location @thin_<%= fetch(:application) %>_<%= fetch(:stage) %> { # rewrite Headers for correct behavior proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host:$server_port; proxy_redirect off; <%= magic_render("nginx/rails_cache_server") %> # pass request to thin upstream proxy_pass http://thin_<%= fetch(:application) %>_<%= fetch(:stage) %>_cluster; } }