ubuntu14.04下配置apache虚拟主机

avatar 2017年02月24日14:33:45 4 3226 views
博主分享免费Java教学视频,B站账号:Java刘哥

第一步、新建项目文件夹

在计算机根目录新建wwwroot文件夹,然后在wwwroot里新建video文件夹,在video里新建index.html,里面随便写点东西。待会儿,我们要通过在地址栏输入video.imooc.com来访问我们这个wwwroot文件夹下的video项目 顺便附图

第二步、在sites-available里创建配置文件video.conf

sites-available在/etc/apache2/下,然后在sites-available文件夹内新建文件video.conf,粘贴以下代码
  1. <VirtualHost *:80>
  2.     # The ServerName directive sets the request scheme, hostname and port that
  3.     # the server uses to identify itself. This is used when creating
  4.     # redirection URLs. In the context of virtual hosts, the ServerName
  5.     # specifies what hostname must appear in the request's Host: header to
  6.     # match this virtual host. For the default virtual host (this file) this
  7.     # value is not decisive as it is used as a last resort host regardless.
  8.     # However, you must set it for any further virtual host explicitly.
  9.     #ServerName www.example.com
  10.         ServerName   video.imooc.com
  11.     ServerAdmin webmaster@localhost
  12.     DocumentRoot /wwwroot/video
  13.     # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
  14.     # error, crit, alert, emerg.
  15.     # It is also possible to configure the loglevel for particular
  16.     # modules, e.g.
  17.     #LogLevel info ssl:warn
  18.     ErrorLog ${APACHE_LOG_DIR}/error.log
  19.     CustomLog ${APACHE_LOG_DIR}/access.log combined
  20.         <Directory /wwwroot/video>
  21.              Options FollowSymLinks
  22.              AllowOverride None
  23.              Require all granted
  24.         </Directory>
  25.     # For most configuration files from conf-available/, which are
  26.     # enabled or disabled at a global level, it is possible to
  27.     # include a line for only one particular virtual host. For example the
  28.     # following line enables the CGI configuration for this host only
  29.     # after it has been globally disabled with "a2disconf".
  30.     #Include conf-available/serve-cgi-bin.conf
  31. </VirtualHost>
  32. # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
带#部分也就是注释部分可以忽略,主要是改ServerName,DocumentRoot和Directory里的内容,只有这三处要改。然后保存。

第三步、创建video.conf软链接到sites.enabled

sites-enabled同样是在apache2文件夹下,就是它来发挥作用。而刚才的sites-available是不起作用的,它的作用就是作为配置文件,备份的感觉。如果不想要那个虚拟主机配置了,只需要删除sites-enabled下的软连接就可以,不需要改sites-available的文件。下次又想要弄那个虚拟主机啦,只需要再创一个软链接就可以啦。如图

第四步、修改hosts文件

hosts文件在etc目录下,找不到的话可以在根目录搜索 建议大家用vim打开编辑,并加入一行代码
  1. 127.0.0.1     video.imooc.com
然后保存即可  

第五步、重启apache,在浏览器里预览效果

在所有操作完毕后重启apache,然后, 在浏览器地址栏输入:video.imooc.com ,效果如图
  最后附一下刚才操作的常用shell命令 1.在根目录新建wwwroot文件夹和三个子文件夹video,bbs,oa
  1. sudo mkdir -p /wwwroot/{video,bbs,oa}
2.进入wwwroot文件夹
  1. cd /wwwroot/
3.显示文件夹内的文件
  1. ls或者ll
4.在video里创建index.html
  1. cd video
  2. sudo vim index.html
5.vim内常用命令
  1. Esc    切换到命令模式
  2. :wq   保存并退出
  3. :%d   清除编辑器内容
  4. ggVG 全选复制
  5. x       删除
  6. u       撤销
  7. /aaaa   搜索aaaa
  8. yy      复制当前行
6.复制000-default.conf为video.conf
  1. sudo cp 000-default.conf video.conf
7.在sites-enabled目录下创建sites-available/video.conf的软链接,并取名video.conf
  1. sudo ln -s ../sites-available/video.conf video.conf
8.重启apache
  1. sudo service apache2 restart
9.重命名(将a改成a.txt)
  1. sudo mv a a.txt
10.删除(将a.txt删除)
  1. sudo rm a.txt
11.待续
更多文章 ubuntu14.04 下 mysql 存储目录迁移 ubuntu14.04下配置apache虚拟主机 ubuntu14.04 安装phpmyadmin 和配置   本文地址:http://liuyanzhao.com/1978.html 转载请注明
  • 微信
  • 交流学习,有偿服务
  • weinxin
  • 博客/Java交流群
  • 资源分享,问题解决,技术交流。群号:590480292
  • weinxin
avatar

发表评论

avatar 登录者:匿名
匿名评论,评论回复后会有邮件通知

  

已通过评论:1   待审核评论数:0
  1. avatar 明月登楼

    不错呀!备案成功了!恭喜呀!