Through CNAME
Amazon recommends to achieve that, is through a CNAME in your domain to have something like http://images.mywebsite.com/flowers/flower.jpg.
To have this, you have to create a bucket called just like the host (images.mywebsite.com), and add a CNAME record in your domain that points to your bucket.
The CNAME record should be something like this:
images.mywebsite.com CNAME images.mywebsite.com.s3.amazonaws.com.
More information can be found on the official documentation of Amazon S3.
Proxied frontend web server
However, if the previous option still doesn't fit on what you need, you can go with the second option, which is tweaking the frontend web server to act as proxy when specifics url are being accessed.
If you are using Nginx, you can use HttpProxyModule to do this, and you have to add this configuration to your nginx.conf file:
location ~* ^/images/(.*) {
set $s3_bucket 'your_bucket.s3.amazonaws.com';
set $url_full '$1';
proxy_http_version 1.1;
proxy_set_header Host $s3_bucket;
proxy_set_header Authorization '';
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header Set-Cookie;
proxy_ignore_headers "Set-Cookie";
proxy_buffering off;
proxy_intercept_errors on;
resolver 172.16.0.23 valid=300s;
resolver_timeout 10s;
proxy_pass http://$s3_bucket/$url_full;
}
With this, you can retrieve your S3 file using an url like: http://www.mywebsite.com/images/flowers/flower.jpg
The downside of this option, is that the webserver will retrieve the file by his own to deliver it to the user, causing some slowness.