It's possible to run some web servers in some systems in virtual networks with virtualization, however, opening to the public all of web servers are not so easy because some global IP address is also needed, but getting some global IP address takes many costs. Therefore, it becomes neccessary to use the function of virtual hostings which Apache has.
Well, here is the example to configure virtual hostings. Following example is done as domain name[server-linux.info (root directory[/var/www/html])], virtual domain name[virtual.info (root directory[/home/fedora/public_html])].
[1] Add virtual domain name in DNS first.
Quote:
[root@ns ~]# vi /etc/named.conf
// add them in 'view "internal"' section
zone "virtual.info" IN {
type master;
file "virtual.info.lan";
allow-update { none; };
};
// add them in 'view "external"' section
zone "virtual.info" IN {
type master;
file "virtual.info.wan";
allow-update { none; };
};
[root@ns ~]# cp /var/named/server-linux.info.lan /var/named/virtual.info.lan
[root@ns ~]# cp /var/named/server-linux.info.wan /var/named/virtual.info.wan
[root@ns ~]# vi /var/named/virtual.info.lan
// change for environment of virtual.info
$TTL86400
@IN
SOA
ns.server-linux.info. root.virtual.info.
(
2007061401
;Serial
3600
;Refresh
1800
;Retry
604800
;Expire
86400
;Minimum TTL
)
IN
NS
ns.server-linux.info.
IN
A
192.168.0.17
IN
MX 10
mail.server-linux.info.
wwwIN
A
192.168.0.18
mailIN
A
192.168.0.19
[root@ns ~]# vi /var/named/virtual.info.wan
// change for environment of virtual.info
$TTL86400
@IN
SOA
ns.server-linux.info. root.virtual.info.
(
2007061401
;Serial
3600
;Refresh
1800
;Retry
604800
;Expire
86400
;Minimum TTL
)
IN
NS
ns.server-linux.info.
IN
A
172.16.0.82
>
IN
MX 10
mail.server-linux.info.
>
wwwIN
A
172.16.0.82
mailIN
A
172.16.0.82
[root@ns ~]# /usr/sbin/bind-chroot-admin -e
// enable chroot
Stopping named:[ OK ]
Starting named:[ OK ]
[root@ns ~]# dig www.virtual.info.
;; ANSWER SECTION:
www.virtual.info. 86400 IN A 192.168.0.18
|
[2] Configuration on Apache
Quote:
[root@www ~]# vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80 // line 971: make valid
<VirtualHost *:80>// bottom: add these lines
DocumentRoot /var/www/html
ServerName www.server-linux.info
ErrorLog logs/server-linux.info-error_log
CustomLog logs/server-linux.info-access_log common
SuexecUserGroup cent cent// suexec enabled
</VirtualHost>
<VirtualHost *:80>// bottom: add these lines
DocumentRoot /home/cent/public_html
ServerName www.virtual.info
ErrorLog logs/virtual.info-error_log
CustomLog logs/virtual.info-access_log common
</VirtualHost>
[root@www ~]# vi /etc/httpd/conf.d/ssl.conf
NameVirtualHost *:443
// line 19: add this line
<VirtualHost *
:443>// line 81: change
SuexecUserGroup cent cent
// line 86: add this line
// add in the bottom of the file: configuration for virtual.info for SSL
<VirtualHost *:443>
DocumentRoot "/home/cent/public_html"
ServerName www.virtual.info:443
ErrorLog logs/virtual.info_ssl_error_log
TransferLog logs/virtual.info_ssl_access_log
LogLevel warn
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/certs/server.key
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
[root@www ~]# /etc/rc.d/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
|
[3] Access to the page that is made in
(2) of [3] section. It's OK if following page is shown.
Quote:
[root@www ~]# cd /var/www/html
[root@www ~]# chmod 700 index.cgi
[root@www html]# ll
total 8
-rwx------ 1 cent cent 211 2007-06-14 19:53 index.cgi
-rw----r-- 1 cent cent 122 2007-06-14 19:29 index.html
|
Access to https too and make sure it's working.
[4] Make a test page for [virtual.info] and make sure it's working. It's OK if following page is shown. [root@www ~]# cd /home/cent/public_html
[root@www public_html]# vi index.cgi
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print <<"EOM";
<html>
<body>
<div style="width:100%;font-size:40px;font-weight:bold;text-align:center">
Virtual Host Test Page<br>
owned by cent </div>
</body>
</html>
EOM
exit;
[root@www public_html]# chown cent. index.cgi
[root@www public_html]# chmod 705 index.cgi
[root@www public_html]# ll
total 4
-rwx---r-x 1 cent cent 240 2007-06-14 19:13 index.cgi
Access to https too and make sure it's working.