# Attachment\_fu and virtual hosts on S3

**URL:** <https://www.ruby-forum.com/t/attachment-fu-and-virtual-hosts-on-s3/122749>\
**Category:** Rails\
**Created:** [December 11, 2007, 7:14pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-virtual-hosts-on-s3/122749 "2007-12-11T19:14:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@rohit](https://www.ruby-forum.com/u/rohit)\
**Post date:** [December 11, 2007, 7:14pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-virtual-hosts-on-s3/122749/1 "2007-12-11T19:14:40Z")

</div>

Hey,

I’ve gotten attachment\_fu working well with Amazon S3.

The only problem is that I don’t know how to generate public URLs that  
contain my much-cooler virtual S3 host names, e.g.  
‘[images.mydomain.com](http://images.mydomain.com)’ with the plugin.

Attachment\_fu has a ‘:server’ configuration option, which will change  
‘[s3.amazonaws.com](http://s3.amazonaws.com)’ to whatever host name you specify.  
Unfortunately, setting this to your virtually-hosted bucket name  
(‘[images.mydomain.com](http://images.mydomain.com)’) results in a URL like this:

[http://images.mydomain.com](http://images.mydomain.com):/images.mydomain.com/path/to/file

which does not work, of course.

Does anyone know how I can configure the plug to use my slick virtual  
host names and generate this:

[http://images.mydomain.com/path/to/file](http://images.mydomain.com/path/to/file)

? Am I missing something obvious (very likely)? Or will I need to roll  
my own URL-substitution scheme?

Thanks so much for any help you can provide.

---

<div class="post-metadata">

**Author:** ![rohit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/41988e/32.png) [@rohit](https://www.ruby-forum.com/u/rohit)\
**Post date:** [December 11, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-virtual-hosts-on-s3/122749/2 "2007-12-11T19:41:11Z")

</div>

Rohit \<rohitkg@…\> writes:

> Hey,
> 
> I’ve gotten attachment\_fu working well with Amazon S3.
> 
> The only problem is that I don’t know how to generate public URLs that  
> contain my much-cooler virtual S3 host names, e.g.  
> ‘[images.mydomain.com](http://images.mydomain.com)’ with the plugin.

The trick is to create an S3 bucket named “[images.mydomain.com](http://images.mydomain.com)” on S3,  
then create a CNAME DNS record for that domain that points  
to [s3.amazonsaws.com](http://s3.amazonsaws.com)

You will not be able to generate secure urls (ssl) for your custom  
domain  
since S3 uses its own certificates and there is no way for you to issue  
one  
for your domain.

Hope that helps.
