Friday, 15 January 2010

serving nginx static files from a subdomain (remove server) -



serving nginx static files from a subdomain (remove server) -

i'm using nginx route incoming requests subdomain specific server. how configure nginx serve static files same server?

server { server_name subdomain.xyz.com; location / { proxy_http_version 1.1; proxy_redirect off; proxy_pass http://10.123.456.78:8000; proxy_pass_header server; proxy_set_header host $http_host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-scheme $scheme; proxy_set_header upgrade $http_upgrade; proxy_set_header connection "upgrade"; proxy_read_timeout 864000; } location /static/ { autoindex on; alias /static/; } }

in case, incoming requests subdomain.xyz.com rerouted 10.123.456.78:8000. requests static files still on local server (the 1 running nginx).

how route static files remote server? , how enable both caching , gzip compression of static files?

it's quite simple:

gzip on; gzip_types text/plain application/json; # or gzip *; proxy_cache_path /data/nginx/cache keys_zone=one:10m; location /static/? { proxy_cache one; proxy_pass http://10.123.456.78:8000/path/to/static/files; }

i recommend gzipping them source instead (on server 10.123.456.78).

nginx

No comments:

Post a Comment