Skip to content

Instantly share code, notes, and snippets.

@RahulMahale
Created January 2, 2018 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RahulMahale/b97a93ee57432497ce7da9461e86a980 to your computer and use it in GitHub Desktop.
Save RahulMahale/b97a93ee57432497ce7da9461e86a980 to your computer and use it in GitHub Desktop.
upstream unicorn {
# This is the socket we configured in unicorn.rb
server unix:/opt/myapp/shared/tmp/sockets/unicorn.sock
fail_timeout=0;
}
upstream ws {
server localhost:3001;
}
upstream api {
server localhost:80;
}
server {
server_name _ proxy_protocol;
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
listen 80 ;
location /api/ {
proxy_set_header X-INTERNAL TRUE;
proxy_set_header Host $host;
proxy_pass http://api;
}
# Websocket support
location /websocket {
proxy_pass http://ws;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_read_timeout 86400;
proxy_buffering off;
proxy_redirect off;
# IE8 Websocket support - uses CORS and HTTP streaming
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
# Tell client that this pre-flight info is valid for 20 days
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-INTERNAL FALSE;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_read_timeout 60s;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
# If you don't find the filename in the static files
# Then request it from the unicorn server
if (!-f $request_filename) {
proxy_pass http://unicorn;
break;
}
}
root /opt/myapp/current/public;
try_files $uri @unicorn;
}
server {
server_name localhost;
listen 81;
location /health_check {
proxy_pass http://unicorn;
}
}
server {
server_name localhost ;
listen 9000;
location /api/ {
proxy_set_header X-INTERNAL TRUE;
proxy_set_header Host $host;
proxy_pass http://api;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment