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.