Apache配置虚拟主机
流程解说
Apache加载配置时会首先加载apache.conf文件(配置文件的入口)
apache.conf文件以include关键字将其他配置文件包含在其中.
- 有助于修改配置
- 按属性分开放置,配置灵活
核心配置:
mods-* 存放Apache模块配置文件sites-*** 存放虚拟主机的配置文件**
关键词available表示可以使用;enabled表示已启用的
enabled通过ln -s命令建立available的软连接
Apache会在加载配置过程中将所有软连接一次性全部加载,以方便软连接误删时再次建立软连接启动模块
通过终端工具在服务器创建目录
创建新目录(wwwroot)
- $mkdir -p /wwwroot/{test01,test02,test03} //集合方式创建目录
分别在这三个文件中加入html文件,都加上区分的内容
设置配置文件
$sudo cp 000-defaule.conf shop.conf //(同理复制成bbs.conf、oa.conf)
修改配置文件
$sudo vi shop.conf //(同理修改bbs.conf、oa.conf)
添加:ServerName shop.test03.com修改:DocumentRoot /wwwroot/shop
修改Apache配置文件
$sudo vi /etc/apache2/apache2.conf
添加:
<Directory /wwwroot/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ServerName localhost:80
建立软链接
- $cd /etc/apache2/sites-enabled
- $sudo ln -s ../sites-availables/shop.conf shop.conf //(同理建立bbs.conf和os.conf的软连接)
- $sudo service apache2 restart //重启Apache
最后在宿主主机的浏览器中输入二级域名看是否显示对应内容
换成aliyun的源
- $sudo vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
- 记得要把里面内容的全部删掉后替换,替换后更新下服务器
重装Lamp环境
- $sudo apt-get install tasksel
- $sudo tasksel
- 用空格选中 basic ubuntu server lamp server 先去掉,一路选‘是’
- $sudo tasksel //然后重新安装就OK了
配置遇到的问题
xxxx忘了,是说哪个文件错误
解决:发现是VirtualHost:80>没闭合
Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
*解决:在apache2.conf里面添加*ServerName localhost:80**后才正常运行
心得:
- 不懂就度娘
- 会看输出的错误信息很重要,能省很多事~~
特别感谢 @坏老师 的精心指导
本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可。