Serving static files with amazon s3 vs nginx

Nginx is going to be faster for site assets like CSS, nav images, etc. If the client browser already has an open connection for the dynamic page, and keepalives are setup it will use the same connection.

You can now back CloudFront with EC2 hosted content so S3 is no longer a requirement at that level. In addition you can use cloudfront with django generated, but not frequently changing content. You can use nginx's built in caching for semi dynamic content. If you are going to have to run a server for the django portion anyway, it is not much extra work.

If the files you need to host are larger, then S3 starts to look better because the disk performance on smaller EC2 instances is not ideal.

In the end, unless you are dealing with dozens of requests per second, both options are going to be close enough that it will be difficult to measure the differences.


There are many things that can play into this, but if it's an option, I would just serve directly out of S3 if you can. Performance would be at least as good or possibly better than using nginx, and it gives you an easy path to start using AWS's CloudFront CDN in the future if need be.


As Coeus Blue mentioned above, it depends on your use case scenario. If your site needs to load as quickly as possible, all resources should be on the same domain (subdomains are separate) as DNS queries can take 1-2ms on a very fast connection or 40-50ms on a bad connection.

DNS calls are normally cached, so on any site with multiple external resources this wouldn't make a massive difference in speed because of DNS lookups.

However, S3 is likely to be faster than an EC2 instance serving the same file with nginx/Apache. S3 storage is cheaper than EBS (and you'd need EFS for a cluster of nginx/Apache webservers) and S3 internet outbound transfers are cheaper than EC2 outbound transfer if I'm not mistaken