{"id":2486,"date":"2013-10-13T07:49:02","date_gmt":"2013-10-12T23:49:02","guid":{"rendered":"http:\/\/rmohan.com\/?p=2486"},"modified":"2013-10-13T09:07:21","modified_gmt":"2013-10-13T01:07:21","slug":"rhce-exam-post-apache","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2486","title":{"rendered":"RHCE EXAM POST &#8211; Apache"},"content":{"rendered":"<p>RHCE training notes &#8211; Apache<\/p>\n<p>Linux under Apache, package is httpd. Httpd main distribution file is \/etc\/httpd\/conf\/httpd.conf, its configuration instructions are primarily<br \/>\ndivided into three parts :<br \/>\nthe control of the Apache server part ( the &#8216;global environment );<br \/>\ndefine the parameters of the primary or default services directive;<br \/>\nvirtual host setting parameters.<br \/>\nHttpd plethora of relevant information , will not elaborate here , this experiment is a combination of dns and apache virtual host site release.<\/p>\n<p>Experimental platform is CentOS 6.4, environment:<\/p>\n<p>Apache server DNS server cum<\/p>\n<p>Host Name : rmohan IP Address : 192.168.1.40<\/p>\n<p>Client Tester<br \/>\nHost Name : station IP address : 192.168.1.2<br \/>\nPreparation:<\/p>\n<p>DNS and Apache installed the apprrmriate software , you can directly use yum to install and set up boot<\/p>\n<p>[root @ rmohan ~] # yum install httpd bind bind-chroot bind-util*<\/p>\n<p>[root @ rmohan ~] # chkconfig httpd on<\/p>\n<p>[root @ rmohan ~] # chkconfig named on<\/p>\n<p>[root @ rmohan ~] # service httpd start<\/p>\n<p>[root @ rmohan ~] # service named start<\/p>\n<p>One , first configure a DNS server<\/p>\n<p>1 Configure the primary distribution file \/etc\/named.conf<\/p>\n<p>In the rmtions {} , locate and modify the contents of the following three :<br \/>\nlisten-on port 53 {any;}; # parentheses content to any<br \/>\nlisten-on-v6 port 53 {any;}; # to any<br \/>\nallow-query {any;}; # to any<\/p>\n<p>2 Configure the zone configuration file , at the end custom zone ( defined here only positive analytical , reverse lookup is not defined )<\/p>\n<p>Modified as follows:<\/p>\n<p>[root @ rmohan ~] # cat \/etc\/named.rfc1912.zones<br \/>\nOmit part &#8230;&#8230; &#8230;&#8230;<br \/>\nzone &#8220;msn.com&#8221; IN {<br \/>\ntype master;<br \/>\nfile &#8220;rm.com.zone&#8221;;<br \/>\nallow-update {none;};<br \/>\n} ;<br \/>\nzone &#8220;rm.com&#8221; IN {<br \/>\ntype master;<br \/>\nfile &#8220;msn.com.zone&#8221;;<br \/>\nallow-update {none;};<br \/>\n} ;<\/p>\n<p>3 in the \/var\/named\u00a0 data files created rm.com.zone and msn.com.zone<br \/>\n[root @ rmohan ~] # cd \/var\/named\/<br \/>\n[root @ rmohan ~] # cp -p named.localhost rm.com.zone<br \/>\n[root @ rmohan ~] # cp -p named.localhost msn.com.zone<br \/>\nThe final contents of the two files is as follows ( in fact, is the same ) :<br \/>\n[root @ rmohan named] # cat rm.com.zone<br \/>\n$ORIGIN rm.com.<br \/>\n$TTL 1D<br \/>\n@\u00a0\u00a0\u00a0\u00a0\u00a0 SOA ns1.rm.com.\u00a0 root.rm.com. (<br \/>\n0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; serial<br \/>\n1D\u00a0\u00a0\u00a0\u00a0\u00a0 ; refresh<br \/>\n1H\u00a0\u00a0\u00a0\u00a0\u00a0 ; retry<br \/>\n1W\u00a0\u00a0\u00a0\u00a0\u00a0 ; expire<br \/>\n3H )\u00a0\u00a0\u00a0 ; minimum<br \/>\n@\u00a0\u00a0\u00a0\u00a0 IN\u00a0\u00a0 NS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ns1.rm.com.<br \/>\nwww\u00a0\u00a0\u00a0 IN\u00a0\u00a0 A\u00a0\u00a0\u00a0\u00a0\u00a0 192.168.1.40<br \/>\nns1\u00a0\u00a0\u00a0\u00a0 IN\u00a0\u00a0 A\u00a0\u00a0\u00a0\u00a0\u00a0 192.168.1.40<br \/>\n@\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IN\u00a0\u00a0 A\u00a0\u00a0\u00a0 192.168.1.40<\/p>\n<p>[root @ rmohan named] # cat msn.com.zone<br \/>\n$ORIGIN msn.com.<br \/>\n$TTL 1D<br \/>\n@\u00a0\u00a0\u00a0\u00a0\u00a0 SOA ns1.msn.com.\u00a0 root.msn.com. (<br \/>\n0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; serial<br \/>\n1D\u00a0\u00a0\u00a0\u00a0\u00a0 ; refresh<br \/>\n1H\u00a0\u00a0\u00a0\u00a0\u00a0 ; retry<br \/>\n1W\u00a0\u00a0\u00a0\u00a0\u00a0 ; expire<br \/>\n3H )\u00a0\u00a0\u00a0 ; minimum<br \/>\n@\u00a0\u00a0\u00a0\u00a0 IN\u00a0\u00a0 NS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ns1.msn.com.<br \/>\nwww\u00a0\u00a0\u00a0 IN\u00a0\u00a0 A\u00a0\u00a0\u00a0\u00a0\u00a0 192.168.1.40<br \/>\nns1\u00a0\u00a0\u00a0\u00a0 IN\u00a0\u00a0 A\u00a0\u00a0\u00a0\u00a0\u00a0 192.168.1.40<br \/>\n@\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 IN\u00a0\u00a0 A\u00a0\u00a0\u00a0 192.168.1.40<\/p>\n<p>[root @ rmohan named] # cd<br \/>\n[root @ rmohan ~] #<\/p>\n<p>4 Restart named service<br \/>\n[root @ zoro ~] # service named restart<br \/>\nStrmping named:. [OK]<br \/>\nStarting named: [OK]<\/p>\n<p>Two , Apache server configuration<\/p>\n<p>1 . First, create a test file need to use the main surface , as follows:<br \/>\n[root @ rmohan html] # ls<br \/>\nindex.html rm msn<br \/>\n[root @ rmohan html] # cat index.html<br \/>\nthis is home page<br \/>\nserver: 192.168.1.40<\/p>\n<p>[root @ rmohan html] # cat rm\/index.html<br \/>\nthis is rm page<br \/>\nserver: 192.168.1.40<\/p>\n<p>[root @ rmohan html] # cat msn\/index.html<br \/>\nthis is mns page<br \/>\nserver: 192.168.1.40<\/p>\n<p>(2) modify the main feature file \/etc\/httpd\/conf\/httpd.conf<\/p>\n<p>First enable NameVirtualHost field, which is a name-based virtual hosts specify an IP address, * indicates the machine &#8216;s IP address currently used .<br \/>\nNameVirtualHost *: 80 # this line is commented out by default , to remove its previous #<br \/>\nThen in the end of the file add the following:<br \/>\n&lt;VirtualHost *:80&gt;<\/p>\n<p># ServerAdmin webmaster@dummy-host.example.com<br \/>\nDocumentRoot \/var\/www\/html # document root directory. By default, all requests from this directory,<br \/>\nServerName 192.168.1.40 # machine &#8216;s name, said that with the IP address or domain name<br \/>\n# ErrorLog logs \/dummy-host.example.com-error_log # You can specify the error log storage directory ,<br \/>\nif not specified, the default is \/etc\/httpd\/logs\/access_log Lane<br \/>\n# CustomLog logs\/dummy-host.example.com-access_log common<br \/>\n&lt;\/VirtualHost&gt;<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/rm<br \/>\nServerName www.rm.com<br \/>\n&lt;\/ VirtualHost&gt;<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/msn<br \/>\nServerName www.msn.com<br \/>\n&lt;\/ VirtualHost&gt;<\/p>\n<p>3 Restart httpd service<\/p>\n<p>[root @ rmohan ~] # service httpd restart<br \/>\nStrmping httpd: [OK]<br \/>\nStarting httpd: httpd: apr_sockaddr_info_get () failed for zoro<br \/>\nhttpd: Could not reliably determine the server&#8217;s fully qualified domain name, using 127.0.0.1 for ServerName<br \/>\n[OK]<\/p>\n<p>Third, the client test<\/p>\n<p>1 Test DNS correctly<br \/>\n[root @ station ~] # nslookup www.rm.com<br \/>\nServer: 192.168.1.40<br \/>\nAddress: 192.168.1.40 # 53<\/p>\n<p>Name: www.rm.com<br \/>\nAddress: 192.168.1.40<\/p>\n<p>[root @ station ~] # cat \/etc\/resolv.conf<br \/>\nnameserver 192.168.1.40<\/p>\n<p>[root @ station ~] # nslookup www.msn.com<br \/>\nServer: 192.168.1.40<br \/>\nAddress: 192.168.1.40 # 53<\/p>\n<p>Name: www.msn.com<br \/>\nAddress: 192.168.1.40<\/p>\n<p>These results without exception, which means that the DNS server running.<\/p>\n<p>2 Test page views<br \/>\nVisit http:\/\/192.168.1.40 using firefox, the returned results:<br \/>\nthis is home page server: 192.168.1.40<\/p>\n<p>Visit http:\/\/www.rm.com using firefox, the returned results:<br \/>\nthis is rm page server: 192.168.1.40<\/p>\n<p>Visit http:\/\/www.msn.com using firefox, the returned results:<br \/>\nthis is msn page server: 192.168.1.40<\/p>\n<p>Fourth, to further debug<\/p>\n<p>1 main httpd on the server with the file \/etc\/httpd\/conf\/httpd.conf in NameVirtualHost<br \/>\ncommented ( previously enabled , and now re- comment ) , and then restart httpd, and then view the test results.<\/p>\n<p>To the client to access the site , you will find ,<br \/>\nwhether it is http:\/\/192.168.1.40, http:\/\/www.rm.com, or http:\/\/www.msn.com,<br \/>\nthe result returned is &#8220;this is home page server: 192.168.1.40 &#8220;, that is the main surface http:\/\/192.168.1.40 content.<\/p>\n<p>2 In the above rmeration 1 , based on the then &#8220;ServerName 192.168.1.40&#8221; delete the contents of the virtual host that virtual host configuration read:<br \/>\nOmit part &#8230;&#8230; &#8230;&#8230;<br \/>\n# NameVirtualHost *: 80<br \/>\nOmit part &#8230;&#8230; &#8230;&#8230;<br \/>\n&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/rm<br \/>\nServerName www.rm.com<br \/>\n&lt;\/ VirtualHost&gt;<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/msn<br \/>\nServerName www.msn.com<br \/>\n&lt;\/ VirtualHost&gt;<\/p>\n<p>After editing , restart httpd.<\/p>\n<p>And then use the client browser access , whether it is http:\/\/192.168.1.40, http:\/\/www.rm.com, or http:\/\/www.msn.com, the returned results are &#8220;this is rm page server: 192.168.1.40 &#8220;, that is the main surface http:\/\/www.rm.com content.<\/p>\n<p>3 In the above rmeration on the basis of two , and then NameVirtualHost enabled , the upcoming primary service httpd file \/ etc \/ httpd \/ conf \/ httpd.conf NameVirtualHost before the comment character # remove , modify, complete, restart httpd.<\/p>\n<p>And then use the client browser access, access http:\/\/192.168.1.40 and http:\/\/www.rm.com, the returned results are &#8220;this is rm page server: 192.168.1.40&#8221;, visit http:\/\/ www.msn.com result returned is &#8220;this is msn page server: 192.168.1.40&#8221;<\/p>\n<p>Based on the above three rmerations , it can be concluded :<\/p>\n<p>If hpptd primary service file , # NameVirtualHost *: 80 is commented out ( default is commented out ) , then the httpd virtual function is not turned on, this time with the master file regardless of how many virtual hosts write ( corresponding in , to the specified DocumentRoot directory to create site pages , home must be index.html), eventually only the first one ( written on trm ) effect , namely client access where ServerName, ultimately points to the first ServerName the corresponding page .<\/p>\n<p>Conclusion II enabled virtual function, the main station ( This article is http:\/\/192.168.1.40, corresponding to the \/ var \/ www \/ html \/ index.html), have written to the virtual host inside, otherwise they would not be accessed . Such as rmerating three , access http:\/\/192.168.1.40 when , in fact, is not the main station visit , but the first virtual host http:\/\/www.rm.com page.<\/p>\n<p>Fifth, the access control<\/p>\n<p>In the above configuration file hosting www.msn.com last example .<\/p>\n<p>Use the virtual host where &lt;Directory&gt; container to set access control.<\/p>\n<p>1 . The virtual host configuration changes to the following:<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/msn<br \/>\nServerName www.msn.com<br \/>\n&lt;Directory &#8220;var\/www\/html\/msn&#8221;&gt;<br \/>\norder allow, deny # Allow first , refused to<br \/>\nallow from 192.168.1. # allowed content , visit here allows 192.168.1.0 network<br \/>\ndeny from 192.168.1.123 # reject the content , where visitors refused to host 192.168.1.123<br \/>\n&lt;\/ Directory&gt;<br \/>\n&lt;\/ VirtualHost&gt;<br \/>\nRestart httpd.<\/p>\n<p>At this time , IP address is 192.168.1.123 host can not access www.msn.com home , there is the Apache test page , in the \/etc\/httpd\/logs\/access_log logs , you can see 403 error, as follows:<br \/>\n192.168.1.123 &#8211; [14\/May\/2013: 07:13:55 +0800] &#8220;GET \/ HTTP\/1.1&#8221; 403 5039 &#8220;-&#8221; &#8220;Mozilla\/5.0 (X11; U; Linux i686; en-US; rv: 1.9.2.24) Gecko\/20111104 Red Hat\/3.6.24-3.el6_1 Firefox\/3.6.24 &#8221;<br \/>\nIn addition to 192.168.1.123 outside , 192.168.1.0 subnet other hosts , can be a normal visit www.msn.com homepage.<\/p>\n<p>(2) modify the virtual host configuration to the following ( as compared with the rmeration 1 , access control reverse the order ) :<br \/>\n&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/msn<br \/>\nServerName www.msn.com<br \/>\n&lt;Directory &#8220;var\/www\/html\/msn&#8221;&gt;<br \/>\norder deny, allow # first refusal , after allowing<br \/>\nallow from 192.168.1.1<br \/>\ndeny from 192.168.1.123<br \/>\n&lt;\/Directory&gt;<br \/>\n&lt;\/ VirtualHost&gt;<\/p>\n<p>Restart httpd.<\/p>\n<p>At this point , 192.168.1.0 subnet to all hosts , including 192.168.1.123, you can normally access www.msn.com homepage.<\/p>\n<p>3 . The virtual host configuration changes to the following ( as compared with rmerating two to allow and deny the contents of the swap for a moment ) :<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/msn<br \/>\nServerName www.msn.com<br \/>\n&lt;Directory &#8220;var\/www\/html\/msn&#8221;&gt;<br \/>\norder deny, allow # first refusal , after allowing<br \/>\nallow from 192.168.1.123<br \/>\ndeny from 192.168.1.<br \/>\n&lt;\/Directory&gt;<br \/>\n&lt;\/VirtualHost&gt;<\/p>\n<p>Restart httpd.<\/p>\n<p>At this time , IP address is 192.168.1.123 hosts can access www.msn.com home , in addition to 192.168.1.123 outside , 192.168.1.0 subnet other hosts can not access www.msn.com homepage.<br \/>\n4 Modify the virtual host configuration to the following ( as compared with rmerating three , access control sequence reversed ; compared with 2 , access control sequence is inverted, and the refusal to allow the content exchanged ; compared with one that allows and denial of the contents of the exchanged ) :<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\nDocumentRoot \/var\/www\/html\/msn<br \/>\nServerName www.msn.com<br \/>\n&lt;Directory &#8220;var\/www\/html\/msn&#8221;&gt;<br \/>\norder allow, deny # Allow first , refused to<br \/>\nallow from 192.168.1.123<br \/>\ndeny from 192.168.1.123<br \/>\n&lt;\/Directory&gt;<br \/>\n&lt;\/VirtualHost&gt;<\/p>\n<p>At this point , 192.168.1.0 subnet to all hosts , including 192.168.1.123, do not have access to www.msn.com homepage.<\/p>\n<p>Based on the above four rmerations, explains what is wrong ? Dizziness, and that is not clear . Combination of two problems in the practical work,<br \/>\nprobably will not write it,<br \/>\nthe purpose of this experiment in terms of the demand for the same network segment , using only deny statements ,<br \/>\ndo not use allow statements will be more easily achieve access control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RHCE training notes &#8211; Apache<\/p>\n<p>Linux under Apache, package is httpd. Httpd main distribution file is \/etc\/httpd\/conf\/httpd.conf, its configuration instructions are primarily divided into three parts : the control of the Apache server part ( the &#8216;global environment ); define the parameters of the primary or default services directive; virtual host setting parameters. Httpd plethora [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2486"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2486"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2486\/revisions"}],"predecessor-version":[{"id":2490,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2486\/revisions\/2490"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}