Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.