Apache 如何在ubuntu 13.10中创建虚拟主机
我正在使用Ubuntu13.10操作系统和LAMP,Apache2.4 我想在apache上创建一个虚拟主机。我尝试了一些代码,但没有成功 进行了以下修改。但它不起作用 首先,我将Apache 如何在ubuntu 13.10中创建虚拟主机,apache,ubuntu,virtualhost,lamp,ubuntu-13.10,Apache,Ubuntu,Virtualhost,Lamp,Ubuntu 13.10,我正在使用Ubuntu13.10操作系统和LAMP,Apache2.4 我想在apache上创建一个虚拟主机。我尝试了一些代码,但没有成功 进行了以下修改。但它不起作用 首先,我将HostnameLookups off更改为HostnameLookups ononetc\apache2\apache2.conf文件。然后我添加了下面的代码 <VirtualHost *:80> ServerName local.scholarships.theiet.in DocumentRoot /
HostnameLookups off
更改为HostnameLookups on
onetc\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>
ServerName local.scholarships.theiet.in
DocumentRoot/home/www/my_project/public_html
选项-索引
要求所有授权
DirectoryIndex.php
允许超越所有
重新启动apache后,我运行了http://localhost/
。该站点未加载
运行
http://localhost/
以下是如何在Apache/Ubuntu上创建Virtual主机:
My 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>
为了避免键入长url,例如代替
http://localhost/path/directory/file/...
您只需在地址栏中输入您的主机名即可:
your_host_name
站点可用目录中的配置文件文件名现在必须以“.conf”结尾,因此在/etc/apache2/sites available/add您的.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>
(如果以后需要禁用,请使用$sudo a2dispatite example.com)
您可能还需要在/etc/hosts文件中添加一行:
127.0.0.1 example.com
别忘了,尽管您已使用a2ensite将该站点添加到apache,但您还需要重新启动apache。这是在ubuntu 13.10中创建虚拟主机的另一种方法 下面的示例显示如何创建虚拟主机 步骤1:在
/home/user/www/
步骤2:在/etc/apache2/apache2.conf中将主机名查找关闭更改为主机名查找打开
步骤3:在/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>
步骤6:打开浏览器并运行http://site1.com/
重新启动apache“sudo:无法初始化策略插件”时出现错误,请尝试此操作,这是完全不同的-以上是与虚拟主机问题相关的两个高质量答案。如果您有更多问题,请创建新的帖子。但为了更有帮助,我认为askubuntu网站上已经解决了这个问题(re sudo):)
127.0.0.1 example.com
<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>
sudo a2ensite site1.com
sudo /etc/init.d/apache2 restart