虚拟主机
2015-07-28 16:14
127 查看
虚拟主机
机架式服务器,按厚度来区分,标准的服务器按U来区分,交换机是标准的1U设备。
xeon *2
(1)分类
基于IP的虚拟主机: 一台服务器,多个IP,搭建多个网站
基于端口的虚拟主机 一台服务器,一个ip,搭建多个网站,每个网络使用不同端口访问
基于名字的虚拟主机 一台服务器,一个ip,搭建多个网站,每个网站使用不同域名访问
(2)步骤:
来自为知笔记(Wiz)
机架式服务器,按厚度来区分,标准的服务器按U来区分,交换机是标准的1U设备。
xeon *2
(1)分类
基于IP的虚拟主机: 一台服务器,多个IP,搭建多个网站
基于端口的虚拟主机 一台服务器,一个ip,搭建多个网站,每个网络使用不同端口访问
基于名字的虚拟主机 一台服务器,一个ip,搭建多个网站,每个网站使用不同域名访问
(2)步骤:
① 解析试验域名
www.sina.com
www.sohu.com
C:\WINDOWS\system32\drivers\etc\hosts windows
/etc/hosts Linux
打开host文件,在其后面输入:(host优先级默认比DNS高,所以会先解析host)
192.168.20.128 www.sina.com
192.168.20.128 www.sohu.com
② 规划网站主目录
/share/sina--------------www.sina.com
/share/sohu ------------ www.sohu.com
③ 修改配置文件
vi /usr/local/apache2/etc/httpd.conf
Include etc//extra/httpd-vhosts.conf
#打开虚拟主机配置文件
vi /usr/local/apache2/etc/extra/httpd-vhosts.conf
对目录设置权限:
<Directory "/share/sina">
Options Indexes
AllowOverride None
Require all granted
</Directory>
<Directory "/share/sohu">
Options Indexes
AllowOverride None
Require all granted
</Directory>
写网站的相关信息:
<VirtualHost 192.168.20.128>(注意:后边不能加端口号:加上就成了基于端口号的虚拟机了)
#注意,只能写ip
ServerAdmin webmaster@sina.com
#管理员邮箱
DocumentRoot "/share/sina"
#网站主目录
ServerName www.sina.com
#完整域名
ErrorLog "logs/sina-error_log"
#错误日志
CustomLog "logs/sina-access_log" common
#访问日志
</VirtualHost>
<VirtualHost 192.168.20.128>
ServerAdmin webmaster@sohu.com
DocumentRoot "/share/sohu"
ServerName www.sohu.com
ErrorLog "logs/sohu.com-error_log"
CustomLog "logs/sohu.com-access_log" common
</VirtualHost>
rewrite 重写功能
在URL中输入一个地址,会自动跳转到另一个
(1)域名跳转 www.sina.com ------> www.sohu.com
[root@localhost ~]# vi /usr/local/apache2/etc/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so(开启147行)
#打开重写模块,记得重启apache
修改配置文件,使sina目录的 .htaccess文件生效
[root@localhost etc]# vi /usr/local/apache2/etc/extra/httpd-vhosts.conf
<Directory "/share/sina">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
[root@localhost etc]# vi /share/sina/.htaccess
RewriteEngine on
#开启rewrite功能
RewriteCond %{HTTP_HOST} www.sina.com
把以www.sina.com 开头的内容赋值给HTTP_HOST变量
RewriteRule .* http://www.sohu.com
.* 输入任何地址,都跳转到http://www.sohu.com
(2)静态网页向动态网页跳转
修改配置文件
<Directory "/usr/local/apache2/htdocs/sohu">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
vi /usr/local/apache2/htdocs/sohu/.htaccess
RewriteEngine on
ewriteRule index(\d+).html index.php?id=$1
# 输入index(数值).html时,跳转到index.php文件,同时把数值当成变量传入index.php
常用子配置文件
httpd-autoindex.conf apache系统别名
httpd-default.conf 线程控制 *
httpd-info.conf 状态统计网页
httpd-languages.conf 语言编码 *
httpd-manual.conf apache帮助文档
httpd-mpm.conf 最大连接数 *
MaxRequestWorkers 250 (默认worker MPM模块生效)
httpd-multilang-errordoc.conf 错页面 *
httpd-ssl.conf ssl安全套接字访问
httpd-userdir.conf 用户主目录配置
httpd-vhosts.conf 虚拟主机
www.sina.com
www.sohu.com
C:\WINDOWS\system32\drivers\etc\hosts windows
/etc/hosts Linux
打开host文件,在其后面输入:(host优先级默认比DNS高,所以会先解析host)
192.168.20.128 www.sina.com
192.168.20.128 www.sohu.com
② 规划网站主目录
/share/sina--------------www.sina.com
/share/sohu ------------ www.sohu.com
③ 修改配置文件
vi /usr/local/apache2/etc/httpd.conf
Include etc//extra/httpd-vhosts.conf
#打开虚拟主机配置文件
vi /usr/local/apache2/etc/extra/httpd-vhosts.conf
对目录设置权限:
<Directory "/share/sina">
Options Indexes
AllowOverride None
Require all granted
</Directory>
<Directory "/share/sohu">
Options Indexes
AllowOverride None
Require all granted
</Directory>
写网站的相关信息:
<VirtualHost 192.168.20.128>(注意:后边不能加端口号:加上就成了基于端口号的虚拟机了)
#注意,只能写ip
ServerAdmin webmaster@sina.com
#管理员邮箱
DocumentRoot "/share/sina"
#网站主目录
ServerName www.sina.com
#完整域名
ErrorLog "logs/sina-error_log"
#错误日志
CustomLog "logs/sina-access_log" common
#访问日志
</VirtualHost>
<VirtualHost 192.168.20.128>
ServerAdmin webmaster@sohu.com
DocumentRoot "/share/sohu"
ServerName www.sohu.com
ErrorLog "logs/sohu.com-error_log"
CustomLog "logs/sohu.com-access_log" common
</VirtualHost>
rewrite 重写功能
在URL中输入一个地址,会自动跳转到另一个
(1)域名跳转 www.sina.com ------> www.sohu.com
[root@localhost ~]# vi /usr/local/apache2/etc/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so(开启147行)
#打开重写模块,记得重启apache
修改配置文件,使sina目录的 .htaccess文件生效
[root@localhost etc]# vi /usr/local/apache2/etc/extra/httpd-vhosts.conf
<Directory "/share/sina">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
[root@localhost etc]# vi /share/sina/.htaccess
RewriteEngine on
#开启rewrite功能
RewriteCond %{HTTP_HOST} www.sina.com
把以www.sina.com 开头的内容赋值给HTTP_HOST变量
RewriteRule .* http://www.sohu.com
.* 输入任何地址,都跳转到http://www.sohu.com
(2)静态网页向动态网页跳转
修改配置文件
<Directory "/usr/local/apache2/htdocs/sohu">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
vi /usr/local/apache2/htdocs/sohu/.htaccess
RewriteEngine on
ewriteRule index(\d+).html index.php?id=$1
# 输入index(数值).html时,跳转到index.php文件,同时把数值当成变量传入index.php
常用子配置文件
httpd-autoindex.conf apache系统别名
httpd-default.conf 线程控制 *
httpd-info.conf 状态统计网页
httpd-languages.conf 语言编码 *
httpd-manual.conf apache帮助文档
httpd-mpm.conf 最大连接数 *
MaxRequestWorkers 250 (默认worker MPM模块生效)
httpd-multilang-errordoc.conf 错页面 *
httpd-ssl.conf ssl安全套接字访问
httpd-userdir.conf 用户主目录配置
httpd-vhosts.conf 虚拟主机
来自为知笔记(Wiz)
相关文章推荐
- easyui dataBox 增加一天,减少一天
- cordova开发ios炸鸡
- 如何实现php图片等比例缩放
- linux 查看进程的命令3(lsof)
- Qt Creator管理多个项目
- Shiro权限框架
- LeetCode题解——Sort List
- 坑爹的BOM PHP
- Apache HTTP Server windows环境下载安装启动
- UVA 725 Division
- jdom创建XML文档
- 81进制,用多进制方式把一个长长的整数变短
- ios 判断字符串中是否包含中文
- 206.Reverse Linked List(单链表逆置)
- 步步为营(十四)常用数据结构(7)STL-Queue(队列)priority_queue(优先队列)
- 西天取经后续
- jquery移除select下所有的option选项
- SYSAUX表空间使用率高问题处理
- 极客班GeekBand - C++面向对象高级开发 - 2
- nodejs npm常用命令