开发者

Associate a domain name to a directory in Apache

开发者 https://www.devze.com 2023-03-14 20:46 出处:网络
I have an Ubuntu dedicated server, and I have 2 domain names. The first one is relate开发者_StackOverflow社区d to the directory \'/var/www/\' and the second one is too, I didn\'t know how to associate

I have an Ubuntu dedicated server, and I have 2 domain names. The first one is relate开发者_StackOverflow社区d to the directory '/var/www/' and the second one is too, I didn't know how to associate the second one to another directory like '/var/www/site2/' Can you help me ? Thank you !


To host multiple domains on the same server with different directories of their own, you need to use the VirtualHost config directive. Inside each one you can specify their own set of configurations (by default the configuration file is stored at /etc/apache2/sites-enabled/000-default.conf):

NameVirtualHost *:80

<VirtualHost *:80>
        ServerName example.com
        DocumentRoot /var/www/site1
        <Directory /var/www/site1>
            Options -Indexes
        </Directory>
</VirtualHost>

<VirtualHost *:80>
        ServerName another-example.com
        DocumentRoot /var/www/site2
        <Directory /var/www/site2>
            Options +Indexes
        </Directory>
</VirtualHost>

The first one lives in /var/www/site1 and has directory indexing turned off. The other is in /var/www/site2 and has directory indexing turned on. You can specify pretty much most configs to be virtualhost specific - ie, custom logging, use of modules such as php or perl, and ServerAlias, among much more. See http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号