Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to make a separate domain for images

I want to set up a domain called img.mydomain.com. It will be a virtual domain that just like my actual domain except for one difference: it will only serve files that end in .jpg .jpeg .gif .png etc. This way I can refer to img.mydomain.com/some_image.jpg. it will speed up the page speed by making the browser think that it's two separate domains (google page speed analyzer is always nagging me to do this).

I'm running apache on a linux server. Should I do this in httpd.conf? If so, what is my first step?

like image 761
pg. Avatar asked Oct 25 '11 22:10

pg.


1 Answers

create 2 folder for each domains (for example):

  • /var/www/domain.com
  • /var/www/img.domain.com/

here's what you can put in your httpd.conf

<VirtualHost *:80>
  DocumentRoot "/var/www/domain.com"
  ServerName domain.com
  ServerAlias domain.com www.domain.com
  <Directory "/var/www/domain.com">
    allow from all
    Options +Indexes
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "/var/www/img.domain.com/"
  ServerName img.domain.com
  ServerAlias img.domain.com
  <Directory "/var/www/img.domain.com/">
    allow from all
    Options +Indexes
  </Directory>
</VirtualHost>
like image 189
James M. Avatar answered Sep 21 '22 00:09

James M.