如何在Ubuntu中配置多个apache站点?


0

我想在apache下配置多个网站。我将我的网站文件复制到

/var/www/site1
/var/www/site2
...
/var/www/site10

如何在用户写入时配置apache加载不同的站点:

http://myserver/site1
..
http://myserver/site10

谢谢

Answers:


2

您需要设置Apache VirtualHost。在Ubuntu中,这些位于/etc/apache2/sites-available/<my site>

在这种情况下,您的虚拟主机可能如下所示:

<VirtualHost *:80>
    ServerName <myserver>
    DocumentRoot /var/www # Point Apache to your web directory

    <Directory />
        Options -Indexes # Don't allow Apache to show a listing of the directory if someone navigates to http://myserver/
        AllowOverride All # Allow .htaccess files in each site directory to be read
    </Directory>
</VirtualHost>

这是最简单的设置,可以帮助您启动和运行。创建此虚拟主机文件后/etc/apache2/sites-available,运行sudo a2ensite <mysite>以启用该站点,然后重新启动apachesudo service apache2 restart

导航到http:// myserver /,您应该获得访问被拒绝页面,但导航到http:// myserver / site1,您应该看到正确的站点。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.