0

我正在使用 ubuntu 13.10 操作系统和 LAMP、Apache 2.4。

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

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

首先,我更改HostnameLookups offHostnameLookups 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/

4

3 回答 3

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
于 2014-02-26T06:56:27.193 回答
1

您在站点可用目录中的配置文件文件名现在必须以“.conf”结尾,因此在 /etc/apache2/sites-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。

于 2014-02-26T07:10:33.807 回答
0

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

下面的例子展示了如何创建一个虚拟主机,

第 1 步:创建一个名为site1.comon的 PHP 项目/home/user/www/

第 2 步:更改HostnameLookups offHostnameLookups onin/etc/apache2/apache2.conf

第 3 步:创建一个名为site1.com.confon/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/

尝试这个

于 2014-02-26T12:45:26.033 回答