如何在ubuntu 13.10中创建虚拟主机
-
21-12-2019 - |
题
我使用的是 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
这是创建的另一种方式 ubuntu 13.10 中的虚拟主机
下面的例子展示了如何创建一个虚拟主机,
步骤1: :创建一个名为的 PHP 项目 site1.com
在 /home/user/www/
第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/
尝试这个
其他提示
以下是在 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>
请注意,我创建了 服务器名称, ,这是我的新主机的名称。
您可以在 /etc/hosts 文件中添加新的主机名,如下所示:
127.0.0.1 your_host_name
为了不输入长网址,例如代替
http://localhost/path/directory/file/...
您只需输入 你的主机名 在地址栏中:
your_host_name
site-available 目录中的配置文件名现在必须以“.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。