ubuntu 下 apache 服务器虚拟主机的配置

学习笔记 马富天 2016-09-23 15:30:13 84 0

【摘要】在阿里云购买了一个服务器(Linux ubuntu),有两个域名:www.mafuitan.net 和 blog.mafutian.net 这两个,此时先将这两个域名在阿里云服务器中添加域名的解析。然后在服务器的 apache 配置文件下面做一些修改。

需要修改的配置文件是:

  1. vi /etc/apache2/sites-available/000-default

原本的内容如下:

  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 www.mafutian.net
  11.         ServerAlias www.mafutian.net
  12.         DocumentRoot /var/www/mafutian
  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.         # For most configuration files from conf-available/, which are
  21.         # enabled or disabled at a global level, it is possible to
  22.         # include a line for only one particular virtual host. For example the
  23.         # following line enables the CGI configuration for this host only
  24.         # after it has been globally disabled with "a2disconf".
  25.         #Include conf-available/serve-cgi-bin.conf
  26. </VirtualHost>

修改为如下:

  1. <VirtualHost *:80>
  2.         DocumentRoot "/var/www/www"
  3.         ServerName www.mafuitan.net
  4.         ServerAlias www.mafutian.net
  5.         <Directory "/var/www/www">
  6.                 Options FollowSymLinks Indexes
  7.                 AllowOverride All
  8.                 Order deny,allow
  9.                 Allow from all
  10.                 Require all granted
  11.         </Directory>
  12. </VirtualHost>
  13. <VirtualHost *:80>
  14.         DocumentRoot "/var/www/blog"
  15.         ServerName blog.mafutian.net
  16.         ServerAlias blog.mafutian.net
  17.         <Directory "/var/www/blog">
  18.                 Options FollowSymLinks Indexes
  19.                 AllowOverride All
  20.                 Order deny,allow
  21.                 Allow from all
  22.                 Require all granted
  23.         </Directory>
  24. </VirtualHost>

重启 Apache 服务器:

  1. service apache2 restart

另外可能需要修改目录 /var/www/blog 的权限,将这个目录下面的所有文件及子目录的权限设为 777:

  1. chmod -R 777 /var/www/blog

然后访问:http://www.mafutian.net 访问的是服务器的 /var/www/www 这个目录

访问:http://blog.mafutian.net 访问的是服务器的 /var/www/blog 这是目录

(注意:不需要修改 hosts 文件)

版权归 马富天个人博客 所有

本文标题:《ubuntu 下 apache 服务器虚拟主机的配置》

本文链接地址:http://www.mafutian.com/209.html

转载请务必注明出处,小生将不胜感激,谢谢! 喜欢本文或觉得本文对您有帮助,请分享给您的朋友 ^_^

0

0

上一篇《 C语言二分查找法 》 下一篇《 windows 下面如何运行 cpp 文件 》

暂无评论

评论审核未开启
表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情 表情
验证码

TOP10

  • 浏览最多
  • 评论最多