ubuntu下设置虚拟domain

参考:http://www.cnblogs.com/ylan2009/archive/2012/02/25/2368028.html

ln 命令的学习
http://blog.csdn.net/coNowen/article/details/7251128

什么是vhost?


Vhost是apache服务的虚拟主机,通过配置不同的vhost,可以在同一台apache主机上运行不同的web应用。

如果你是一位PHP学习者,你想通过两个不同的应用test1和test2学习不同的知识,或者进行对比测试。你就可以创建两个test1目录和test2目录,里面分别存放test1和test2两个工程。通过将这两个工程映射给两个虚拟主机vhost1和vhost2,你就可以分别运行test1和test2了。访问test1:http://test1.localhost http://test2.localhost。

下面我们就来学习一下,如何配置apache创建vhost。

如何配置vhost?

首先,是创建一个虚拟站点,test1.localhost

Cd /etc/apache2

ls

看到一个名为site-available的目录,该目录存放的vhost主机的配置文件

Cd site-available

看到一个default文件,这就是一个defalut虚拟主机的配置文件

Cp default site.loalhost

修改site.localhost文件

Vim site.localhost

<VirtualHost *:80>
DocumentRoot /home/web/your domain
ServerName common-system
<Directory /home/web/your domain>
                AllowOverride All
                Options Indexes FollowSymLinks MultiViews
                Order allow,deny
                Allow from all
</Directory>
</VirtualHost>



保存文件

检查配置有误错误

sudo apache2ctl configtest

没问题的话提示

AH00112: Warning: DocumentRoot [XXX] does not exist
Syntax OK


重启apache服务
sudo /etc/init.d/apache2 restart

执行http://your domain,看到了什么??

如果是远程访问,还需要加上dns或者在本机的windows C:\Windows\System32\drivers\etc\hosts上加上ip domain映射。

最后访问:
Forbidden

You don't have permission to access / on this server.
Apache/2.4.10 (Ubuntu) Server at devlocal.yaf.nmg.com.hk Port 8


网上的结果都是说修改httpd.conf。但是根本没这个文件。应该是修改apache2.conf

改成

<Directory />
	Options FollowSymLinks
	AllowOverride All
        Allow from all
	#Require all denied
</Directory>
<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride All
	Allow from all	
#Require all granted
</Directory>


修改之后重启下apache。访问domain又出现
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred,and the actions you performed just before this error.

More information about this error may be available in the server error log.


可以到/var/log/apache2/log/error.log查看错误消息。
[Sat Aug 01 07:49:21.342372 2015] [:error] [pid 27605] [client 192.168.3.227:62114] script '/var/www/html/web/yaf/application/index.PHP' not found or unable to stat
[Sat Aug 01 07:56:16.678085 2015] [authz_core:error] [pid 27607] [client 192.168.3.227:52460] AH01630: client denied by server configuration: /home/web/yaf/
[Sat Aug 01 07:56:32.949625 2015] [mpm_prefork:notice] [pid 27599] AH00169: caught SIGTERM,shutting down

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...