如何在ubuntu 13.10中创建虚拟主机

时间:2014-02-26 06:46:17

标签: apache ubuntu virtualhost lamp ubuntu-13.10

我使用的是ubuntu 13.10操作系统和LAMP,Apache 2.4。

我想在apache上创建一个虚拟主机。我尝试了一些代码,但它没有用。

进行以下修改。但它不起作用。

首先,我在HostnameLookups off文件上将HostnameLookups on更改为etc\apache2\apache2.conf。然后我添加了以下代码,

<VirtualHost *:80>
ServerName local.scholarships.theiet.in
DocumentRoot /home/www/my_project/public_html
<Directory path_to_code_base/public>
    Options -Indexes
    Require all granted
    DirectoryIndex index.php
    AllowOverride All
</Directory>
</VirtualHost>

重新启动apache后,我运行了http://localhost/。该网站未加载。

如何在运行http://localhost/

时加载我的网站

3 个答案:

答案 0 :(得分:1)

以下是如何在Apache / Ubuntu上创建虚拟主机:

我的000-default.conf文件:

<VirtualHost *:80>
    DocumentRoot /var/www/php/frbit/l4blog/public/
    <Directory /var/www/php/frbit/l4blog/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>
    ServerName l4blog
</VirtualHost>

请注意,我创建了 ServerName ,这是我新主机的名称。

您可以在/ etc / hosts文件中添加新主机名,如下所示:

127.0.0.1   your_host_name

为了不输入长网址,例如而不是

http://localhost/path/directory/file/...

您只需在地址栏中输入 your_host_name

your_host_name

答案 1 :(得分:1)

sites-available目录中的配置文件文件名现在必须以“.conf”结尾,因此在/etc/apache2/site-available /中添加.conf文件,以example.com.conf的方式命名;按以下方式对其进行建模:

<VirtualHost *:80>
ServerAdmin you@example.com
    ServerName www.example.com
    DocumentRoot /var/www/example.com
    <Directory />
            Options FollowSymLinks
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
    require all granted
    </Directory>

    ErrorLog /var/log/apache2/example.com.error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/example.com.access.log combined    
</VirtualHost>

使用以下命令在apache中启用它:

$ sudo a2ensite example.com

(如果您以后需要禁用它,请使用$ sudo a2dissite example.com)

您可能还需要在/ etc / hosts文件中添加一行:

127.0.0.1 example.com

不要忘记,虽然您已经使用a2ensite将网站添加到apache,但您还需要重新启动apache。

答案 2 :(得分:0)

这是在ubuntu 13.10中创建虚拟主机的另一种方法

下面的示例显示了如何创建虚拟主机

第1步:在site1.com上创建名为/home/user/www/的PHP项目

第2步:在HostnameLookups off

中将HostnameLookups on更改为/etc/apache2/apache2.conf

第3步:在site1.com.conf上创建名为/etc/apache2/sites-available/的配置文件

将此代码添加到site1.com.conf

<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
ServerAdmin info@site1.com
DocumentRoot /var/www/site1.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/site1.com">
    Options All
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

第4步:然后将127.0.0.1 site1.com添加到/etc/hosts.txt

第5步:打开终端并运行命令,

sudo a2ensite site1.com

sudo /etc/init.d/apache2 restart

第6步:打开浏览器并运行http://site1.com/

试试这个