Apache Basic configuration Management: Apache based on Ip,port and domain name three virtual host configuration method

Source: Internet
Author: User
Tags create directory to domain

Apache Configuration Management

one, based on the port, that is, based on the different ports, the same IP virtual host

virtual hosts with different ports based on the same IP

 
1) vi/etc/http/conf/httpd.conf

2) Change the Listen field to
Listen 80
Listen 8888
(the above setting means using 80 and 8888 Ports)
  
3) Change the virtual host section To:
  <virtualhost 192.168.0.1:80>
Documentroot/var/www/html/website1

ServerName www.website1.com

  </VirtualHost>
<virtualhost 192.168.0.1:8888>;
Documentroot/var/www/html/website2

ServerName www.website2.com

  </VirtualHost>
  
4) Save the above settings
  
5) Create a directory and a paging file:
#mkdir –p/var/www/html/website1
#mkdir –p/var/www/html/website2
#cd/var/www/html/website1
#cat >index.html <<eof
>website1
>eof
#cd/var/www/html/website2
#cat >index.html <<eof
>website2
>eof

Supplemental about Eof:

In the shell, the file delimiter (usually written as eof, You can also write foe or any other String) immediately after the << symbol, meaning that the content after the delimiter will be passed as standard input to the << preceding command

The basic use of the format is This:
Command << EOF
Content Segment
Eof
Enter the entire content segment as the Command.
Your code reads the entire string and assigns it to the list variable with the cat Command.
In fact, it is not necessary to use eof, as long as the "content segment" does not appear in the string, can be used to replace eof, just a start and end of the Logo.

One particular usage has to say:
: << COMMENTBLOCK
Shell Script
COMMENTBLOCK
This is used to annotate the entire script Code. : is an empty statement in the Shell.

Search for here document and you will understand More.

(note: There are directoryindex index.html Index.html.var in/etc/httpd/conf/httpd.conf, which means read-only index.html, not read index.htm, remember)
  
6) Service httpd Restart
  
When you have completed the above settings, you can access it in the following ways:
  
1) Open Browser
  
2) input http://192.168.0.1:80 and http://192.168.0.1:8888
  
 second, based on ip, that is, based on different ip, the same port of the virtual host

        Virtual host based on the same port different IP

1) configuration of different IP addresses:
#cd/etc/  Sysconfig/network-scripts
#cp ifcfg-eth0 ifcfg-eth0:1
#vi ifcfg-eth0:1
Change eth0:1 to:
Device=eth0:1
Onboot=yes
bootproto=static
ipaddr=192.168.0.2
netmask=255.255.255.0

         ifconfig eth0:1 192.168.1.11 is temporarily in effect and needs to be written to the/etc/sysconfig/network-scripts/ifcfg-eth0:1 configuration file
2) Service Network restart
3) vi/etc/httpd/conf/httpd.conf
4) Change the Virtual host section to:
<virtualhost 192.1 68.0.1:80>
documentroot/var/www/html/website1
</virtualhost>
<virtualhost 192.168.0.2:80
Documentroot/var/www/html/website2
</virtualhost>
5) Create directory and paging file:
#mkdir –p/var/www/html/w Ebsite1
#mkdir –p/var/www/html/website2
#cd/var/www/html/website1
#cat >index.html <<eof
&G T;website1
>eof
#cd/var/www/html/website2
#cat >index.html <<eof
>website2
>EO F

After you have completed the above settings, you can access the following ways:

1) Open Browser
2) enter http://192.168.0.1:80 and http://192.168.0.2:80

third, based on the host name, that is, the base of the domain name of the virtual host access
  

3. Access to domain-based virtual hosts

1) Set the domain name mapping with one ip, modify/etc/hosts:

192.168.0.1 www1.example.com
192.168.0.1 www2.example.com


2) Create a directory and a paging file:
#mkdir –p/var/www/html/website1
#mkdir –p/var/www/html/website2
#cd/var/www/html/website1
#cat >index.html <<eof
>website1
>eof
#cd/var/www/html/website2
#cat >index.html <<eof
>website2
>eof
  

3) in the httpd-vhosts.conf Configuration Virtual host Section Is:
Namevirtualhost 192.168.0.1 [namevirtualhost *.80]
<virtualhost www1.example.com>
Documentroot/var/www/html/website1
ServerName www1.example.com
</VirtualHost>
<virtualhost www2.example.com>
Documentroot/var/www/html/website2
ServerName www2.example.com
</VirtualHost>
(note: the above settings can not be omitted Namevirtualhost)


4) when you have completed the above settings, you can access the following methods:
1) Open Browser
2) input http://www1.example.com and http://www2.example.com

Found not properly accessible, the configuration of the virtual included in the http.conf search Vhost This line, and then open the line, and then restart the Service.


in order to use a domain-based virtual host, you must specify the server IP address (and possibly the port) to allow the host to accept the Request. Can be configured with the namevirtualhost Directive. If all IP addresses on the server are used, you can use * as Namevirtualhost parameters. specifying an IP address in the NAMEVIRTUALHOST directive does not cause the server to automatically listen for that IP address . The IP address set here must correspond to a network interface on the Server.

  the next step is for each virtual host Setup <VirtualHost> configuration block that you set up for,<virtualhost> the parameters of the Namevirtualhost directive are the Same. In each <VirtualHost> definition block, there will be at least one ServerName instruction to specify which host and one documentroot instruction to indicate where the contents of this host exist in the Filesystem.

If you add a virtual host to an existing Web server, you must also build a <VirtualHost> definition block for existing Hosts. The contents of servername and DocumentRoot should be consistent with the global, and should be placed at the front of the configuration file, playing the role of the default Host.

Namevirtualhost *:80
<virtualhost *:80>

ServerName *

documentroot/www/

</VirtualHost>

<virtualhost *:80>

ServerName www.test1.com

documentroot/www/test1/

<directory "/www/test1" >

Options Indexes FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

</Directory>

</VirtualHost>

<virtualhost *:80>

ServerName www.test2.com

documentroot/www/test2/

<directory "/www/test2" >

Options Indexes FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

</Directory>

</VirtualHost>

<virtualhost *:80>

ServerName www.test3.com

documentroot/www/test3/

<directory "/www/test3" >

Options Indexes FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

</Directory>

</VirtualHost>


Reference Address:

Http://www.cnblogs.com/hi-bazinga/archive/2012/04/23/2466605.html

http://blog.csdn.net/joliny/article/details/2514293









This article is from the "12214694" blog, please be sure to keep this source http://12224694.blog.51cto.com/12214694/1895589

Apache Basic configuration Management: Apache based on Ip,port and domain name three virtual host configuration method

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.