公司在一台Linux主机192.168.${学号}.155上建设了自己的Web网站。
为节省服务器资源,希望在此服务器上再为销售部建立一个Web网站,与现有网站共用一个IP地址与端口号(80)。
公司对于销售部网站的要求如下:
www.sales${学号}.company.cn访问/var/www/sales_${学号}目录下,主页采用index.htmlroot@company.cnGB2312192.168.${学号}.155初始化配置文件
xxxxxxxxxxcd /usr/share/doc/bind-9.3.3/samplecp etc/*.* /var/named/chroot/etccp var/named/*.* /var/named/chroot/var/named修改 /var/named/chroot/etc/named.conf
xxxxxxxxxxoptions{ query-source port 53; query-source-v6 port 53;
directory "/var/named"; dump-file "data/cache_dump.db"; statistics-file "data/named_stats.txt"; memstatistics-file "data/named_mem_stats.txt";
};include "/etc/named.rfc1912.zones";修改 /var/named/chroot/etc/named.rfc1912.zones
xxxxxxxxxxzone "localdomain" IN { type master; file "localdomain.zone"; allow-update { none; };};zone "localhost" IN { type master; file "localhost.zone"; allow-update { none; };};zone "0.0.127.in-addr.arpa" IN { type master; file "named.local"; allow-update { none; };};zone "sales${学号}.company.cn" IN { type master; file "sales${学号}.company.cn.zone"; allow-update { none; };};zone "${学号}.168.192.in-addr.arpa" IN { type master; file "sales${学号}.company.cn.arp"; allow-update { none; };};
zone"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { type master; file "named.ip6.local"; allow-update { none; };};
zone "255.in-addr.arpa" IN { type master; file "named.broadcast"; allow-update { none; };};
zone "0.in-addr.arpa" IN { type master; file "named.zero"; allow-update { none; };};添加 /var/named/chroot/var/named/sales${学号}.company.cn.zone
xxxxxxxxxx$TTL 86400@ IN SOA @ root ( 42 ; serial (d. adams) 3H ; refresh 15M ; retry 1W ; expiry 1D ) ; minimum
@ IN NS www.sales${学号}.company.cn.www.sales${学号}.company.cn. IN A 192.168.${学号}.155添加 /var/named/chroot/var/named/sales${学号}.company.cn.arp
xxxxxxxxxx$TTL 86400@ IN SOA localhost. root.localhost. ( 1997022700 ; Serial 28800 ; Refresh 14400 ; Retry 3600000 ; Expire 86400 ) ; Minimum@ IN NS www.sales${学号}.company.cn.155.${学号}.168.192.in-addr.arpa. IN PTR www.sales${学号}.company.cn.DNS配置文件:/etc/resolv.conf
xxxxxxxxxx# 在配置文件中添加domain www.sales${学号}.company.cnnameserver 192.168.${学号}.155
# 重启服务service named restartxxxxxxxxxxnslookupwww.sales${学号}.company.cnxxxxxxxxxxuseradd -s /sbin/nologin sales_managerpasswd sales_manageruseradd -s /sbin/nologin saler_${姓名}passwd saler_${姓名}xxxxxxxxxxmkdir /var/www/sales_${学号}chmod 755 /var/www/sales_${学号}vi /var/www/sales_${学号}/index.html
# 创建用户的根目录mkdir /home/sales_manager/public_htmlchmod 755 /home/sales_manager/public_htmlmkdir /home/saler_${姓名}/public_htmlchmod 755 /home/saler_${姓名}/public_html
vi /home/sales_manager/public_html/index.htmlvi /home/saler_${姓名}/public_html/index.html/var/www/sales_${学号}/index.html
xxxxxxxxxx<html lang="en"><head> <meta charset="UTF-8"> <title>销售部主页</title></head><body><h1>This is home page!</h1></body></html>/home/sales_manager/public_html/index.html
xxxxxxxxxx<html lang="en"><head> <meta charset="UTF-8"> <title>销售部经理</title></head><body><h1>This is sales_manager's page!</h1></body></html>/home/saler_${姓名}/public_html/index.html
xxxxxxxxxx<html lang="en"><head> <meta charset="UTF-8"> <title>${姓名}</title></head><body><h1>This is saler_${姓名}'s page!</h1></body></html>/etc/httpd/conf/httpd.conf
service httpd restartxxxxxxxxxxServerTokens OSServerRoot "/etc/httpd"PidFile run/httpd.pidTimeout 120KeepAlive OffMaxKeepAliveRequests 100KeepAliveTimeout 15
<IfModule prefork.c>StartServers 8MinSpareServers 5MaxSpareServers 20ServerLimit 256MaxClients 256MaxRequestsPerChild 4000</IfModule>
<IfModule worker.c>StartServers 2MaxClients 150MinSpareThreads 25MaxSpareThreads 75 ThreadsPerChild 25MaxRequestsPerChild 0</IfModule>
Listen 80 listen 8080
LoadModule auth_basic_module modules/mod_auth_basic.soLoadModule auth_digest_module modules/mod_auth_digest.soLoadModule authn_file_module modules/mod_authn_file.soLoadModule authn_alias_module modules/mod_authn_alias.soLoadModule authn_anon_module modules/mod_authn_anon.soLoadModule authn_dbm_module modules/mod_authn_dbm.soLoadModule authn_default_module modules/mod_authn_default.soLoadModule authz_host_module modules/mod_authz_host.soLoadModule authz_user_module modules/mod_authz_user.soLoadModule authz_owner_module modules/mod_authz_owner.soLoadModule authz_groupfile_module modules/mod_authz_groupfile.soLoadModule authz_dbm_module modules/mod_authz_dbm.soLoadModule authz_default_module modules/mod_authz_default.soLoadModule ldap_module modules/mod_ldap.soLoadModule authnz_ldap_module modules/mod_authnz_ldap.soLoadModule include_module modules/mod_include.soLoadModule log_config_module modules/mod_log_config.soLoadModule logio_module modules/mod_logio.soLoadModule env_module modules/mod_env.soLoadModule ext_filter_module modules/mod_ext_filter.soLoadModule mime_magic_module modules/mod_mime_magic.soLoadModule expires_module modules/mod_expires.soLoadModule deflate_module modules/mod_deflate.soLoadModule headers_module modules/mod_headers.soLoadModule usertrack_module modules/mod_usertrack.soLoadModule setenvif_module modules/mod_setenvif.soLoadModule mime_module modules/mod_mime.soLoadModule dav_module modules/mod_dav.soLoadModule status_module modules/mod_status.soLoadModule autoindex_module modules/mod_autoindex.soLoadModule info_module modules/mod_info.soLoadModule dav_fs_module modules/mod_dav_fs.soLoadModule vhost_alias_module modules/mod_vhost_alias.soLoadModule negotiation_module modules/mod_negotiation.soLoadModule dir_module modules/mod_dir.soLoadModule actions_module modules/mod_actions.soLoadModule speling_module modules/mod_speling.soLoadModule userdir_module modules/mod_userdir.soLoadModule alias_module modules/mod_alias.soLoadModule rewrite_module modules/mod_rewrite.soLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_balancer_module modules/mod_proxy_balancer.soLoadModule proxy_ftp_module modules/mod_proxy_ftp.soLoadModule proxy_http_module modules/mod_proxy_http.soLoadModule proxy_connect_module modules/mod_proxy_connect.soLoadModule cache_module modules/mod_cache.soLoadModule suexec_module modules/mod_suexec.soLoadModule disk_cache_module modules/mod_disk_cache.soLoadModule file_cache_module modules/mod_file_cache.soLoadModule mem_cache_module modules/mod_mem_cache.soLoadModule cgi_module modules/mod_cgi.so
Include conf.d/*.conf
User apacheGroup apache
ServerAdmin root@localhost
UseCanonicalName Off
DocumentRoot "/var/www/html"
<Directory /> Options FollowSymLinks AllowOverride None</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny Allow from all</Directory>
<IfModule mod_userdir.c> UserDir disable sales_manager UserDir public_html</IfModule>
DirectoryIndex index.html index.html.var
AccessFileName .htaccess
<Files ~ "^\.ht"> Order allow,deny Deny from all</Files>
TypesConfig /etc/mime.types
DefaultType text/plain
<IfModule mod_mime_magic.c> MIMEMagicFile conf/magic</IfModule>
HostnameLookups Off
ErrorLog logs/error_log
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" commonLogFormat "%{Referer}i -> %U" refererLogFormat "%{User-agent}i" agent
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all</Directory>
<IfModule mod_dav_fs.c> DAVLockDB /var/lib/dav/lockdb</IfModule>
<Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all</Directory>
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*AddIconByType (IMG,/icons/image2.gif) image/*AddIconByType (SND,/icons/sound2.gif) audio/*AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exeAddIcon /icons/binhex.gif .hqxAddIcon /icons/tar.gif .tarAddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .ivAddIcon /icons/compressed.gif .Z .z .tgz .gz .zipAddIcon /icons/a.gif .ps .ai .epsAddIcon /icons/layout.gif .html .shtml .htm .pdfAddIcon /icons/text.gif .txtAddIcon /icons/c.gif .cAddIcon /icons/p.gif .pl .pyAddIcon /icons/f.gif .forAddIcon /icons/dvi.gif .dviAddIcon /icons/uuencoded.gif .uuAddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tclAddIcon /icons/tex.gif .texAddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..AddIcon /icons/hand.right.gif READMEAddIcon /icons/folder.gif ^^DIRECTORY^^AddIcon /icons/blank.gif ^^BLANKICON^^
AddLanguage ca .caAddLanguage cs .cz .csAddLanguage da .dkAddLanguage de .deAddLanguage el .elAddLanguage en .enAddLanguage eo .eoAddLanguage es .esAddLanguage et .etAddLanguage fr .frAddLanguage he .heAddLanguage hr .hrAddLanguage it .itAddLanguage ja .jaAddLanguage ko .koAddLanguage ltz .ltzAddLanguage nl .nlAddLanguage nn .nnAddLanguage no .noAddLanguage pl .poAddLanguage pt .ptAddLanguage pt-BR .pt-brAddLanguage ru .ruAddLanguage sv .svAddLanguage zh-CN .zh-cnAddLanguage zh-TW .zh-tw
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TWForceLanguagePriority Prefer Fallback
AddDefaultCharset UTF-8
AddType application/x-compress .ZAddType application/x-gzip .gz .tgz
AddHandler type-map var
AddType text/html .shtmlAddOutputFilter INCLUDES .shtml
Alias /error/ "/var/www/error/"
<IfModule mod_negotiation.c><IfModule mod_include.c> <Directory "/var/www/error"> AllowOverride None Options IncludesNoExec AddOutputFilter Includes html AddHandler type-map var Order allow,deny Allow from all LanguagePriority en es de fr ForceLanguagePriority Prefer Fallback </Directory>
</IfModule></IfModule>
BrowserMatch "Mozilla/2" nokeepaliveBrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0BrowserMatch "RealPlayer 4\.0" force-response-1.0BrowserMatch "Java/1\.0" force-response-1.0BrowserMatch "JDK/1\.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefullyBrowserMatch "MS FrontPage" redirect-carefullyBrowserMatch "^WebDrive" redirect-carefullyBrowserMatch "^WebDAVFS/1.[0123]" redirect-carefullyBrowserMatch "^gnome-vfs/1.0" redirect-carefullyBrowserMatch "^XML Spy" redirect-carefullyBrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
NameVirtualHost 192.168.${学号}.155:80
<VirtualHost 192.168.${学号}.155:80> ServerAdmin root@company.cn DocumentRoot /var/www/sales_${学号} ServerName www.sales${学号}.company.cn DirectoryIndex index.html ErrorLog logs/dummy-www.sales${学号}.company.cn-error_logs CustomLog logs/dummy-www.sales${学号}.company.cn-access_log common</VirtualHost>xxxxxxxxxx# 成功访问http://www.sales${学号}.company.cnhttp://www.sales${学号}.company.cn/~saler_${姓名}# 访问失败http://www.sales${学号}.company.cn/~sales_manager在一台Linux网站服务器上建立两个虚拟站点,端口分别为7000和9000,域名为www.${姓名缩写}-IT.com。
站点根目录分别为/var/www/${姓名缩写}1和/var/www/${姓名缩写}2,存放不同网页,并通过域名分别进行访问:
http://www.${姓名缩写}-IT.com:7000http://www.${姓名缩写}-IT.com:9000xxxxxxxxxxmkdir /var/www/${姓名缩写}1vi /var/www/${姓名缩写}1/index.htmlmkdir /var/www/${姓名缩写}2vi /var/www/${姓名缩写}2/index.htmlxxxxxxxxxx nslookup# 输入网址测试# 正向解析www.${姓名}-gz.com.cnmail.${姓名}-gz.com.cn# 反向解析192.168.${学号}.20192.168.${学号}.30shell
xxxxxxxxxx<html lang="en"><head> <meta charset="UTF-8"> <title>${姓名缩写}1</title></head><body><h1>http://www.${姓名缩写}-IT.com:7000</h1></body></html>/var/www/${姓名缩写}2/index.html
xxxxxxxxxx<html lang="en"><head> <meta charset="UTF-8"> <title>${姓名缩写}2</title></head><body><h1>http://www.${姓名缩写}-IT.com:9000</h1></body></html>初始化配置文件
xxxxxxxxxxcd /usr/share/doc/bind-9.3.3/samplecp etc/*.* /var/named/chroot/etccp var/named/*.* /var/named/chroot/var/named修改 /var/named/chroot/etc/named.conf
xxxxxxxxxxoptions{ query-source port 53; query-source-v6 port 53;
directory "/var/named"; dump-file "data/cache_dump.db"; statistics-file "data/named_stats.txt"; memstatistics-file "data/named_mem_stats.txt";
};include "/etc/named.rfc1912.zones";修改 /var/named/chroot/etc/named.rfc1912.zones
xxxxxxxxxxzone "localdomain" IN { type master; file "localdomain.zone"; allow-update { none; };};zone "localhost" IN { type master; file "localhost.zone"; allow-update { none; };};zone "0.0.127.in-addr.arpa" IN { type master; file "named.local"; allow-update { none; };};zone "${姓名缩写}-IT.com" IN { type master; file "${姓名缩写}-IT.com.zone"; allow-update { none; };};zone "${学号}.168.192.in-addr.arpa" IN { type master; file "${姓名缩写}-IT.com.arp"; allow-update { none; };};
zone"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { type master; file "named.ip6.local"; allow-update { none; };};
zone "255.in-addr.arpa" IN { type master; file "named.broadcast"; allow-update { none; };};
zone "0.in-addr.arpa" IN { type master; file "named.zero"; allow-update { none; };};添加 /var/named/chroot/var/named/${姓名缩写}-IT.com.zone
xxxxxxxxxx$TTL 86400@ IN SOA @ root ( 42 ; serial (d. adams) 3H ; refresh 15M ; retry 1W ; expiry 1D ) ; minimum
@ IN NS www.${姓名缩写}-IT.com.www.${姓名缩写}-IT.com. IN A 192.168.${学号}.155添加 /var/named/chroot/var/named/${姓名缩写}-IT.com.arp
xxxxxxxxxx$TTL 86400@ IN SOA localhost. root.localhost. ( 1997022700 ; Serial 28800 ; Refresh 14400 ; Retry 3600000 ; Expire 86400 ) ; Minimum@ IN NS www.${姓名缩写}-IT.com.155.${学号}.168.192.in-addr.arpa. IN PTR www.${姓名缩写}-IT.com.DNS配置文件:/etc/resolv.conf
xxxxxxxxxx# 在配置文件中添加domain www.${姓名缩写}-IT.comnameserver 192.168.${学号}.155
# 重启服务service named restartxxxxxxxxxxnslookupwww.${姓名缩写}-IT.com/etc/httpd/conf/httpd.conf
在此注释下添加(删除其余VirtualHost标签)
xxxxxxxxxx# VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for requests without a known# server name.xxxxxxxxxx<VirtualHost 192.168.${学号}.155:7000> DocumentRoot /var/www/${姓名缩写}1 ServerName www.${姓名缩写}-IT.com DirectoryIndex index.html</VirtualHost>
<VirtualHost 192.168.${学号}.155:9000> DocumentRoot /var/www/${姓名缩写}2 ServerName www.${姓名缩写}-IT.com DirectoryIndex index.html</VirtualHost>修改完毕后重启服务:service httpd restart
xxxxxxxxxx# 成功访问http://www.${姓名缩写}-IT.com:7000http://www.${姓名缩写}-IT.com:9000