Apache deploys three virtual host configurations based on IP address, port, and DNS domain name

1. Apache directory structure
Service directory: /usr/local/httpd
Main configuration file: /usr/local/httpd/confi/http.conf
Web page directory: /usr/local/httpd/htdocs
Service script: /usr/local/httpd /bin/apachectl
execution program: /usr/local/httpd/bin/httpd
Access log: /usr/local/httpd/log/access.log
Error log: /usr/local/httpd/log/error.log
2. Commonly used Global configuration parameters
ServerRoot: Service directory
ServerAdmin: Administrator email
User: User identity for running the service
Group: Group identity for running the service
ServerName: Domain name of the website server
DocumentRoot: Root directory of the web document
Listen: Monitoring IP address, port number
PidFile : The file that saves the PID number of the http process
DirectoryIndex: The default index page file
ErrorLog: The location of the error log file
CustomLog: The location of the access log file
LogLevel: The level of recording qualifications, the default is warn
Timeout: The network connection timeout, the default is 300 seconds
KeepAlive :Whether to maintain the connection, optional On or Off
MaxKeepAliveRequests: The maximum number of requested files per connection status
KeepAliveTimeout: The timeout period to keep the connection
Include: Other configuration files that need to be included
3. Compile and install httpd

3.1 Preparation

Check if httpd is installed
rpm -qa httpd
Uninstall the original httpd
rpm -e httpd

3.2 Compile and install environment

[root@xss httpd-2.2.15]# yum -y install gcc gcc-c++

3.3 Source code compilation and installation

解包:[root@xss httpd-2.2.15]# tar zxf httpd-2.2.15.tar.gz -C /usr/src/

Configuration : [root@xss httpd-2.2.15]# cd /usr/src/httpd-2.2.15/

[root@xss httpd-2.2.15]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --with-included-apr

Compile and install : [root@xss httpd-2.2.15]# make && make install

3.4 Optimizing the Execution Path

[root@xss httpd-2.2.15]# ln -s /usr/local/httpd/bin/* /usr/local/bin
[root@xss httpd-2.2.15]# httpd -v = /usr/local/ httpd/bin/httpd – Insert image description here
3.5 Add httpd system service

[root@xss httpd-2.2.15]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@xss httpd-2.2.15]# vim /etc/init.d/httpd
#!/bin/sh
#chkconfig:35 85 15 //Which Linux levels need to start httpd(3,5); startup sequence number (85); shutdown sequence number (15)
#description:startup for httpd server
Insert image description here
startup

[root@xss httpd-2.2.15]# chkconfig --add httpd

Start httpd service

[root@xss httpd-2.2.15]# service httpd start

Visit 4. Site layout in the browser
Insert image description here

4.1 Virtual host based on IP address

Modify main configuration file

Turn on the virtual host function
[root@xss htdocs]# vim /usr/local/httpd/conf/httpd.conf

Virtual hosts
Include conf/extra/httpd-vhosts.conf

Modify virtual host configuration file

[root@xss htdocs]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.8.137>
ServerAdmin [email protected]
DocumentRoot “/usr/local/httpd/htdocs/mytest1”
ServerName www.mytest1.com
ServerAlias www.dummy-host.example.com
ErrorLog “logs/mytest1.error_log”
CustomLog “logs/mytest1.access_log” common

<VirtualHost 192.168.8.138>
ServerAdmin [email protected]
DocumentRoot “/usr/local/httpd/htdocs/mytest2”
ServerName www.mytest2.com
ErrorLog “logs/mytest2.error_log”
CustomLog “logs/mytest2.access_log ” common

Insert image description here
verification
Insert image description hereInsert image description here
4.2 port-based virtual host

Modify the main configuration file.
Add the monitored port
[root@xss htdocs]# vim /usr/local/httpd/conf/httpd.conf
Listen 80
Listen 8080
Modify the virtual host configuration file
[root@xss htdocs]# vim /usr/local /httpd/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.8.138:80>
ServerAdmin [email protected]
DocumentRoot “/usr/local/httpd/htdocs/mytest1”
ServerName www.mytest1.com
ServerAlias www.dummy-host.example.com
ErrorLog “logs/mytest1.error_log”
CustomLog “logs/mytest1.access_log” common

<VirtualHost 192.168.8.138:8080>
ServerAdmin [email protected]
DocumentRoot “/usr/local/httpd/htdocs/mytest2”
ServerName www.mytest2.com
ErrorLog “logs/mytest2.error_log”
CustomLog “logs/mytest2.access_log” common

Verification
Insert image description here
Insert image description here
4.3 Virtual host based on DNS domain name

Install bind service
[root@xss Packages]# rpm -ivh bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm
configure DNS

Modify main configuration file

Declare two domain
options { directory “/var/named”; };

zone “mytest1.com” IN{
type master;
file “mytest1.com.zone”;

};

zone “mytest2.com” IN{
type master;
file “mytest2.com.zone”;

};
Create parsing file, Insert image description here
write parsing file,
Insert image description here
restart service Insert image description here
, modify virtual host configuration file

[root@xss htdocs]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf

Statement 192.168.8.138 is a virtual host server based on domain name

Insert image description here
Modify network card configuration
Insert image description here
and restart network service

[root@xss named]# service network restart

Verification: This machine can resolve successfully
Insert image description here
Real machine verification : Modify the DNS address of the real machine to the IP address of the virtual machine
Insert image description here
Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_42121397/article/details/109723311