一、配置二级域名

修改hosts文件,模拟dns解析。

位置:/etc/hosts

添加

127.0.0.1  myweb.service.com

二、创建项目目录

apache默认目录是/var

mkdir -p  wwwroot/myweb

然后在目录下,创建index.html

路徑:/var/wwwroot/myweb/index.html

三、apache配置虚拟主机最核心的几个参数

cd  /etc/apache2/sites-available/

default.conf文件

<VirtualHost *:80>

# The ServerName directive sets the request scheme, hostname and port that

# the server uses to identify itself. This is used when creating

# redirection URLs. In the context of virtual hosts, the ServerName

# specifies what hostname must appear in the request's Host: header to

# match this virtual host. For the default virtual host (this file) this

# value is not decisive as it is used as a last resort host regardless.

# However, you must set it for any further virtual host explicitly.

#ServerName www.example.com

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,

# error, crit, alert, emerg.

# It is also possible to configure the loglevel for particular

# modules, e.g.

#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are

# enabled or disabled at a global level, it is possible to

# include a line for only one particular virtual host. For example the

# following line enables the CGI configuration for this host only

# after it has been globally disabled with "a2disconf".

#Include conf-available/serve-cgi-bin.conf

</VirtualHost>

复制,命名为 myweb.conf然后按照实际情况进行配置。

1.加ServerName参数    域名

2.修改DocumentRoot参数   路径

3.如果沒有下面這段,必須加上

DocumentRoot  /var/wwwroot/myweb

<Directory /var/wwwroot/myweb/>

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

</Directory>

例子:

<VirtualHost *:80>

# The ServerName directive sets the request scheme, hostname and port that

# the server uses to identify itself. This is used when creating

# redirection URLs. In the context of virtual hosts, the ServerName

# specifies what hostname must appear in the request's Host: header to

# match this virtual host. For the default virtual host (this file) this

# value is not decisive as it is used as a last resort host regardless.

# However, you must set it for any further virtual host explicitly.

ServerName myweb.service.com  --記得去掉注釋#號

ServerAdmin webmaster@localhost

        DocumentRoot /var/wwwroot/myweb

<Directory var/wwwroot/myweb/>

        Options Indexes FollowSymLinks

        AllowOverride None

        Require all granted

</Directory>

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,

# error, crit, alert, emerg.

# It is also possible to configure the loglevel for particular

# modules, e.g.

#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are

# enabled or disabled at a global level, it is possible to

# include a line for only one particular virtual host. For example the

# following line enables the CGI configuration for this host only

# after it has been globally disabled with "a2disconf".

#Include conf-available/serve-cgi-bin.conf

</VirtualHost>

四、在/etc/apache2/sites-enabled    目录下还要创建软连接。

ln -s ../sites-available/myweb.conf  myweb.conf

***一定要加上後綴名.conf ****

五、完成之后,重启apache---service apache2 restart

现在到浏览器中访问配置好的域名就OK了。

例如myweb.service.com

最新文章

  1. 使用jOrgChart插件, 异步加载生成组织架构图
  2. 非阻塞同步算法与CAS(Compare and Swap)无锁算法
  3. tomcat PermGen space
  4. scala言语基础学习四
  5. 用VS2010开发Android应用的配置方法
  6. 使用git pull时,项目没有更新?
  7. BZOJ 1023
  8. jQuery_第四章_思维图
  9. 【1414软工助教】团队作业6——展示博客(Alpha版本) 得分榜
  10. 编写高质量代码改善java程序的151个建议——[110-117]异常及Web项目中异常处理
  11. linux部署Web项目总结
  12. I2C的小结
  13. 【原】关于AdaBoost的一些再思考
  14. jquery获取table,遍历输出tr中各个td的内容(转载)
  15. c#+arcAE对图层进行各种渲染操作
  16. 洛谷 P5105 不强制在线的动态快速排序
  17. 使用 esxtop 识别存储性能问题
  18. 暂停、恢复CALayer 动画
  19. Howto: Performance Benchmarks a Webserver
  20. codefind.pl

热门文章

  1. 【PKUSC2019】线弦图【计数】【树形DP】【分治FFT】
  2. volatile学习
  3. git多人参与的项目 -> 分支代码如何合并到主干
  4. 十四周学习总结&amp;简易记事本
  5. 云服务器搭建anaconda pytorch torchvision
  6. django写原生sql语句
  7. python 元组和数组
  8. python学习笔记:(九)循环(for和while)
  9. fixture作用范围
  10. java:Hibernate框架2(关联映射(多对一,一对多,一对多双向,一对一主键,一对一唯一外键,多对多双向))