I want to make a separate domain for images

本秂侑毒 提交于 2019-12-10 14:53:05

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/7896548/i-want-to-make-a-separate-domain-for-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!