# Define App Server Upstream <% if fetch(:app_server, nil) %> upstream <%= fetch(:application) %>-app-server { <% if fetch(:app_server_port, nil) %> server 127.0.0.1:<%= fetch(:app_server_port) %> fail_timeout=0; <% elsif fetch(:app_server_socket, nil) %> server unix:<%= fetch(:app_server_socket) %> fail_timeout=0; <% end %> } <% end %> # HTTP Server server { listen 80 deferred; server_name <%= fetch(:domains, ["platan.us", "www.platan.us"]).join(" ") %>; root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; access_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-access.log; error_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-error.log; error_page 404 /404.html; location /404.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; } error_page 500 /500.html; location /500.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; } client_max_body_size 4G; keepalive_timeout 10; <% if fetch(:app_server, nil) %> location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @<%= fetch(:application) %>-app-server; location @<%= fetch(:application) %>-app-server { 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 http; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://<%= fetch(:application) %>-app-server; } <% end %> } <% if fetch(:use_ssl, nil) %> # HTTPS Server server { listen 443 deferred; server_name <%= fetch(:domains, ["platan.us", "www.platan.us"]).join(" ") %>; root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; ssl on; ssl_certificate /home/<%= fetch(:user) %>/ssl/<%= fetch(:application) %>.crt; ssl_certificate_key /home/<%= fetch(:user) %>/ssl/<%= fetch(:application) %>.key; access_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-access.log; error_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-error.log; error_page 404 /404.html; location /404.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; } error_page 500 /500.html; location /500.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; } client_max_body_size 4G; keepalive_timeout 10; <% if fetch(:app_server, nil) %> location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @<%= fetch(:application) %>-app-server; location @<%= fetch(:application) %>-app-server { 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 https; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://<%= fetch(:application) %>-app-server; } <% end %> } <% end %>