Skip to content

Instantly share code, notes, and snippets.

@lulalala
Created August 3, 2012 08:01
Show Gist options
  • Save lulalala/3245632 to your computer and use it in GitHub Desktop.
Save lulalala/3245632 to your computer and use it in GitHub Desktop.
For http://serverfault.com/questions/405264/ ,having problem using try_files
worker_processes 20;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
keepalive_timeout 5 5;
tcp_nodelay on;
gzip on;
gzip_min_length 1100; #1100 20101203
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf/sites-enabled/site.conf;
}
upstream SITE_NAME {
server unix:PATH_TO_PROJECT/shared/pids/thin.0.sock;
}
# asset server
server {
listen 80;
server_name assets.example.com;
expires max;
add_header Cache-Control public;
charset utf-8;
root PATH_TO_PROJECT/current/public;
}
# frontend
server {
listen 80;
server_name .example.com;
charset utf-8;
log_format custom_debug 'request:"$request" $status uri:"$uri"';
access_log logs/example_com/access.log custom_debug;
error_log logs/example_com/error.log debug;
location ~* images/thumb {
root PATH_TO_PROJECT/current/public;
expires max;
break;
}
location ~* ^.+.(jpg|jpeg|gif|png|swf|zip|rar|doc|xls|exe|pdf|ppt|txt|tar)$ {
root PATH_TO_PROJECT/current/public;
expires max;
break;
}
gzip on;
location / {
# serve static cache files
set $cache_dir_2 'home';
if ($host = gas.example.com ) {
set $cache_dir_2 'gas';
}
if ($host = api.example.com ) {
set $cache_dir_2 'api';
}
root PATH_TO_PROJECT/current/public;
# $uri always contains one slash(the first slash but not the last)
try_files /cache/$cache_dir_2$uri/index.html /cache/$cache_dir_2$uri.html @rails;
}
location @rails {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://SITE_NAME;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment