Lamp CentOS Virtual Host Configuration

Source: Internet
Author: User
Tags ldap

1. Virtual host configuration based on different ports

[[Email protected]~]# vi/etc/httpd/conf/httpd.conf

Listen #设置监听不同的虚拟主机需要使用的端口

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: The directory "/VAR/WWW/HTML/80" has been created

mkdir: The directory "/var/www/html/8080" has been created

mkdir: The directory "/var/www/html/8088" has been created


[[Email protected]~]# echo] >/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


View three listening ports


[[Email protected]~]# NETSTAT-TLNP | grep httpd

TCP 0 0::: 8080:::* LISTEN 1285/httpd

TCP 0 0::: +:::* LISTEN 1285/httpd

TCP 0 0::: 8088:::* LISTEN 1285/httpd


Use your own IP address and then open the Web page to test separately.

192.168.3.32

192.168.3.32:8080

192.168.3.32:8088


2, based on different IP address virtual host configuration

First, attach an IP address to the host, and then add two sub-IP addresses.

[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. Domain-based virtual host configuration

The namevirtualhost192.168.3.32:80#apache2.2.xx version requires this option to be turned on and consistent with the following: The 2.4.x version does not require this setting.


<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


We added three records to the local hosts

[[email protected] desktop] #vi/etc/hosts

192.168.3.32 www.80.com

192.168.3.32 www.8080.com

192.168.3.32 www.8088.com

Using the browser test, these three virtual host if the input IP address to access, access is the first, using the domain name can access three content


4, identity-based directory access.

[[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


Browser input HTTP://192.168.3.32/80


5. Directory access based on LDAP authentication

[[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

Browser input http://192.168.3.32/8080

Lamp CentOS Virtual Host Configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.