0

For the moment, I serve my static content (jpg, png, css) from mydomain.com like this:

location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
root /home/www/mydomain/current/web;
add_header        Cache-Control public;
expires        365d;
access_log     off;
}

I'd like to serve it from static.mydomain.com to be "cookie free" and have better performances.

What is better? Add a new server section in my nginx vhost configuration with something like:

server {
    listen  192.168.2.25:80;
    server_name     static.mydomain.com;
    root /home/www/mydomain/current/web;

    location / {
   return 404;
    }

    location ~ \.(?:jpg|css|gif|png|swf|ico|mp3)$ {
add_header        Cache-Control public;
    }
}

Or proxy-pass the request for dynamic content like that (exemple take on nginx wiki):

server { 
listen       192.168.2.25:80;
server_name  www.mydomain.com;

# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/  {
  root    /var/www/virtual/big.server.com/htdocs;
  expires 30d;
}

# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
  proxy_pass      http://127.0.0.1:8080;
}

}

Thanks for your advices.

Nathan
  • 11
  • 2

3 Answers3

1

Your proxy_pass solution wouldn't result in a cookieless domain. Your dynamic content would set cookies on www.mydomain.com and you'd be back where you started (but with additional needless latency).

The first solution is the better of the two, but the best might be something like Amazon's CloudFront CDN with an origin of www.mydomain.com for static content.

ceejayoz
  • 32,910
  • 7
  • 82
  • 106
0

Using proxy-pass will increase the server load somewhat, because every connection for dynamic content will first pass through the proxy and then be handled a second time by the actual server. So if you're having any sort of load issue, I'd recommend the first solution.

Jenny D
  • 27,780
  • 21
  • 75
  • 114
-1

Nginx vhost is better idea but Varnish is something that you should look into .