lamp centos虚拟主机配置
Posted nike_ha
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamp centos虚拟主机配置相关的知识,希望对你有一定的参考价值。
1、基于不同端口的虚拟主机配置
[[email protected]~]# vi /etc/httpd/conf/httpd.conf
Listen 80 #设置监听不同的虚拟主机需要使用的端口
Listen 8080
Listen 8088
<Virtualhost*:80> #三个不同端口的主机
ServerName www.80.com
DocumentRoot /var/www/html/80
</Virtualhost>
<Virtualhost*:8080>
ServerName www.8080.com
DocumentRoot /var/www/html/8080
</Virtualhost>
<Virtualhost*:8088>
ServerName www.8088.com
DocumentRoot /var/www/html/8088
</Virtualhost>
[[email protected]~]# mkdir -pv /var/www/html/{80,8080,8088} #建立三个网页目录
mkdir:已创建目录 "/var/www/html/80"
mkdir:已创建目录 "/var/www/html/8080"
mkdir:已创建目录 "/var/www/html/8088"
[[email protected]~]# echo "80" > /var/www/html/80/index.html #添加网页内容
[[email protected]~]# echo "8080" > /var/www/html/8080/index.html
[[email protected]~]# echo "8088" > /var/www/html/8088/index.html
[[email protected]~]# httpd -t #运行配置文件的语法检查
SyntaxOK
[[email protected]~]# service httpd restart
查看三个监听端口
[[email protected]~]# netstat -tlnp | grep httpd
tcp 0 0 :::8080 :::* LISTEN 1285/httpd
tcp 0 0 :::80 :::* LISTEN 1285/httpd
tcp 0 0 :::8088 :::* LISTEN 1285/httpd
使用自己的IP地址,然后打开网页分别测试。
192.168.3.32
192.168.3.32:8080
192.168.3.32:8088
2、基于不同的ip地址虚拟主机配置
首先给主机附加一个ip地址,再添加两个子IP地址。
[[email protected]~]# ifconfig eth0:0 192.168.3.33 netmask 255.255.255.0 up
[[email protected]~]# ifconfig eth0:1 192.168.3.34 netmask 255.255.255.0 up
[[email protected]~]# vi /etc/httpd/conf/httpd.conf
<Virtualhost192.168.3.32:80>
ServerName www.80.com
DocumentRoot /var/www/html/80
</Virtualhost>
<Virtualhost192.168.3.33:80>
ServerName www.8080.com
DocumentRoot /var/www/html/8080
</Virtualhost>
<Virtualhost192.168.3.34:80>
ServerName www.8088.com
DocumentRoot /var/www/html/8088
</Virtualhost>
[[email protected]~]# httpd -t
SyntaxOK
[[email protected]~]# service httpd restart
3、基于域名的虚拟主机配置
NameVirtualHost192.168.3.32:80#apache2.2.xx版本需要开启此选项,而且要和下面的保持一致;2.4.x版本就不需要此项设置了
<Virtualhost192.168.3.32:80>
ServerName www.80.com
DocumentRoot /var/www/html/80
</Virtualhost>
<Virtualhost192.168.3.32:80>
ServerName www.8080.com
DocumentRoot /var/www/html/8080
</Virtualhost>
<Virtualhost192.168.3.32:80>
ServerName www.8088.com
DocumentRoot /var/www/html/8088
</Virtualhost>
[[email protected]~]# httpd -t
[[email protected]~]# service httpd restart
我们在本地hosts添加三条记录
[[email protected]桌面]#vi /etc/hosts
192.168.3.32 www.80.com
192.168.3.32 www.8080.com
192.168.3.32 www.8088.com
使用浏览器测试,这三个虚拟主机如果输入ip地址来访问的话,访问的都是第一个,使用域名可以访问三个内容
4、基于身份的目录访问。
[[email protected]]# vi /etc/httpd/conf/httpd.conf
<Directory"/var/www/html/80">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
AuthName"user Access"
AuthType Basic
AuthUserFile/var/www/html/htpasswd
Requirevalid-user
</Directory>
[[email protected]]# htpasswd -c /var/www/html/htpasswd admin
Newpassword:
Re-typenew password:
Addingpassword for user admin
[[email protected]]# service httpd restart
浏览器输入http://192.168.3.32/80
5、基于LDAP验证的目录访问
[[email protected]]# vi /etc/httpd/conf/httpd.conf
<Directory"/var/www/html/8080">
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
AuthName"LDAP Access"
AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthLDAPURL"ldap://192.168.2.30:389/ou=People,dc=lbs,dc=com?uid" #设置LDAP地址及OU信息
Requireuser mars #只允许LDAP账户Mars访问
</Directory>
[[email protected]]# service httpd restart
浏览器输入http://192.168.3.32/8080
以上是关于lamp centos虚拟主机配置的主要内容,如果未能解决你的问题,请参考以下文章
centos6.2安装好lamp环境后,要配置虚拟主机的目录 但是找不到apache下的httpd-vhosts.conf