虚拟主机

虚拟主机

机架式服务器,按厚度来区分,标准的服务器按U来区分,交换机是标准的1U设备。
 

xeon    *2

(1)分类

  • 基于IP的虚拟主机: 一台服务器,多个IP,搭建多个网站
  • 基于端口的虚拟主机 一台服务器,一个ip,搭建多个网站,每个网络使用不同端口访问
  • 基于名字的虚拟主机 一台服务器,一个ip,搭建多个网站,每个网站使用不同域名访问

(2)步骤:

解析试验域名

www.sina.com

www.sohu.com

C:WINDOWSsystem32driversetchosts 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 虚拟主机







php是世界上最好的编程语言,没有之一
原文地址:https://www.cnblogs.com/lookphp/p/4683216.html