lamp centos虛擬機器主機配置

來源:互聯網
上載者:User

標籤:

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.