Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Last active July 18, 2018 13:50
Show Gist options
  • Save mustmodify/f73fe4bdf04e25edfe9f4055afd2599c to your computer and use it in GitHub Desktop.
Save mustmodify/f73fe4bdf04e25edfe9f4055afd2599c to your computer and use it in GitHub Desktop.
nginx rails configuration
server {
server_name demo.domain.com;
listen 80;
charset utf-8;
root /home/demo/castle/current/public;
location @rails {
proxy_pass http://localhost:1123;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ cclib
{
add_header spam please_stop_bothering_me;
return 403;
break;
}
location ~ null$ {
add_header mq stupid_mapquest_bug;
return 406;
break;
}
location /assets {
# This isn't working. A request at www.domain.com/assets/abc/xyz should
# for a file at {{ROOT}}/assets/abc/xyz. If not there, serve {{ROOT}}/404.html
# with status 404.
gzip_static on;
expires max;
add_header Cache-Control public;
try_files $uri =404;
}
location / {
# Rails will cache to {{ROOT}} so try there first, even if not
# /assets. Then try Rails. Rails is going to serve a 404 anyway,
# but if for some reason it doesn't, go ahead with that.
try_files $uri @rails;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment