標籤:
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虛擬機器主機配置