{"id":144,"date":"2013-05-27T19:41:54","date_gmt":"2013-05-27T19:41:54","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=144"},"modified":"2013-05-27T19:41:54","modified_gmt":"2013-05-27T19:41:54","slug":"centos-6-apache-web-server","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2013\/05\/27\/centos-6-apache-web-server\/","title":{"rendered":"CentOS 6 &#8211; Apache Web Server"},"content":{"rendered":"<h2>Install, Configure and Secure<\/h2>\n<h3>Environment<\/h3>\n<p>Fresh install of\u00a0<a href=\"http:\/\/www.centos.org\/modules\/tinycontent\/index.php?id=34\" target=\"new\" rel=\"noopener noreferrer\">CentOS-6.3-x86_64-minimal<\/a>\u00a0with the latest updates\u00a0<code>yum update -y<\/code><\/p>\n<blockquote>\n<pre># uname -sro\nLinux 2.6.32-279.22.1.el6.x86_64 GNU\/Linux<\/pre>\n<\/blockquote>\n<p>I used\u00a0<strong>nano<\/strong>\u00a0as the text editor, but you can just as easily use\u00a0<strong>vi<\/strong><\/p>\n<blockquote>\n<div>yum install -y nano<\/div>\n<\/blockquote>\n<h3>Prerequisites<\/h3>\n<p><strong>Configure Firewall<\/strong><\/p>\n<p><em>Make sure you add any other rules not listed here which you are using.<\/em><\/p>\n<div>nano \/etc\/sysconfig\/iptables<\/div>\n<blockquote>\n<pre>*filter\n:INPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT\n-A INPUT -p icmp -j ACCEPT\n-A INPUT -i lo -j ACCEPT\n-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT\n-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT\n-A INPUT -j REJECT --reject-with icmp-host-prohibited\n-A FORWARD -j REJECT --reject-with icmp-host-prohibited\nCOMMIT<\/pre>\n<\/blockquote>\n<div>service iptables restart<\/div>\n<h3>Install<\/h3>\n<p><strong>Install Apache (httpd)<\/strong><\/p>\n<blockquote>\n<div>yum install -y httpd mod_ssl<\/div>\n<\/blockquote>\n<h3>Tune and Secure<\/h3>\n<p><strong>Apache Configuration Files &#8211; A quick explanation<\/strong><\/p>\n<p>When Apache starts, it reads one or more configuration files to see what settings it should have. The first file it normally reads is<code>\/etc\/httpd\/conf\/httpd.conf<\/code>\u00a0which it processes line by line overwriting any previously set variables. For example, if you had on line 6 &#8216;fruit apple&#8217; and then on line 10 &#8216;fruit orange&#8217;, then when Apache has finished reading all configuration files, the value of fruit would be orange as it was the last value for fruit that was read.<\/p>\n<p>There is a special line in a configuration file that tells Apache to pause reading the current file and to read one or more other configuration files before continuing; this line starts with\u00a0<code>Include<\/code>\u00a0such as\u00a0<code>Include conf.d\/*.conf<\/code>\u00a0which tells Apache to read all the files ending in &#8216;.conf&#8217; in the directory &#8216;\/etc\/httpd\/conf.d\/&#8217;, and is the normal procedure on a standard install.<\/p>\n<p>If you also had a value for &#8216;fruit&#8217; in one of the included configuration files, then that value would overwrite the current value for &#8216;fruit&#8217;, however, the final value of &#8216;fruit&#8217; is only determined once Apache has finished reading to the bottom of it&#8217;s initial configuration file, which as mentioned before, is normally\u00a0<code>\/etc\/httpd\/conf\/httpd.conf<\/code>, so if on the last line of &#8216;httpd.conf&#8217; you had\u00a0<code>fruit none<\/code>, then the final value Apache uses would be &#8216;none&#8217;.<\/p>\n<p><strong>Creating a Global config file<\/strong><\/p>\n<p>The best way to manage Apache&#8217;s settings is to create your own configuration files in\u00a0<code>\/etc\/httpd\/conf.d\/<\/code>. This way you can easily see what changes you have made to the system should something need changing, and you can easily revert the system back should something go wrong.<\/p>\n<p>By default, Apache reads\u00a0<code>\/etc\/httpd\/conf\/httpd.conf<\/code>\u00a0as mentioned earlier. Part way through this file, is an\u00a0<code>Include<\/code>\u00a0line which instructs Apache to read all configuration files in the directory &#8216;\/etc\/httpd\/conf.d\/&#8217;. So a good place to create a global configuration file would be inside the &#8216;\/etc\/httpd\/conf.d\/&#8217; directory. As Apache reads files in alphanumeric order, we will prefix characters that will ensure it is read first.<\/p>\n<div>nano \/etc\/httpd\/conf.d\/1.global.conf<\/div>\n<p>Inside this file, add the following which I will explain further on:<\/p>\n<blockquote>\n<pre>SetOutputFilter DEFLATE\nBrowserMatch ^Mozilla\/4 gzip-only-text\/html\nBrowserMatch ^Mozilla\/4\\.0[678] no-gzip\nBrowserMatch \\bMSI[E] !no-gzip !gzip-only-text\/html\nSetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png|pdf)$ no-gzip dont-vary\nHeader append Vary User-Agent env=!dont-vary\n\n<strong>Header append Vary Accept-Encoding<\/strong>\n\n&lt;filesMatch \"\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|js|css|eot|svg|ttf|woff)$\"&gt;\n  Header set Cache-Control \"max-age=604800, public\"\n&lt;\/filesMatch&gt;\n\nHeader always append X-Frame-Options SAMEORIGIN\n\nTraceEnable off\n\nServerTokens Minimal<\/pre>\n<\/blockquote>\n<p><strong>Modify main config file<\/strong><\/p>\n<p>The following settings appear after the\u00a0<code>Include conf.d\/*.conf<\/code>\u00a0line in the\u00a0<code>\/etc\/httpd\/conf\/httpd.conf<\/code>\u00a0file and therefore can&#8217;t be set in our Global config file, as explained earlier.<\/p>\n<div>nano \/etc\/httpd\/conf\/httpd.conf<\/div>\n<blockquote>\n<pre>ServerSignature Off<\/pre>\n<\/blockquote>\n<p>The following line is inside the\u00a0<code>&lt;Directory \"\/var\/www\/html\"&gt;<\/code>\u00a0around line 331.<\/p>\n<blockquote>\n<pre>Options -Indexes FollowSymLinks<\/pre>\n<\/blockquote>\n<h3>Explanation<\/h3>\n<p><strong>Compress Content<\/strong><\/p>\n<p>This configures Apache to compress content if the web browser supports it. Images and PDF&#8217;s are already compressed so are excluded.\u00a0<a href=\"https:\/\/developers.google.com\/speed\/docs\/best-practices\/payload#GzipCompression\" target=\"new\" rel=\"noopener noreferrer\">[Click here to learn more]<\/a><\/p>\n<blockquote>\n<pre>SetOutputFilter DEFLATE\nBrowserMatch ^Mozilla\/4 gzip-only-text\/html\nBrowserMatch ^Mozilla\/4\\.0[678] no-gzip\nBrowserMatch \\bMSI[E] !no-gzip !gzip-only-text\/html\nSetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png|pdf)$ no-gzip dont-vary\nHeader append Vary User-Agent env=!dont-vary<\/pre>\n<\/blockquote>\n<p><strong>Vary: Accept-Encoding<\/strong><\/p>\n<pre>Header append Vary Accept-Encoding<\/pre>\n<p>This configures Apache to tell web browsers that content could come in different formats such as compressed and uncompressed but to treat it the same.\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/7848796\/what-does-varyaccept-encoding-mean\" target=\"new\" rel=\"noopener noreferrer\">[Click here to learn more]<\/a><\/p>\n<p><strong>Cache-Control<\/strong><\/p>\n<blockquote>\n<pre>&lt;filesMatch \"\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|js|css|eot|svg|ttf|woff)$\"&gt;\n  Header set Cache-Control \"max-age=604800, public\"\n&lt;\/filesMatch&gt;<\/pre>\n<\/blockquote>\n<p>This configures Apache to tell web browsers to cache certain types of files for a specified period of time\u00a0<a href=\"http:\/\/httpd.apache.org\/docs\/current\/mod\/mod_headers.html\" target=\"new\" rel=\"noopener noreferrer\">[Click here to learn more]<\/a><\/p>\n<p><strong>Prevent ClickJacking<\/strong><\/p>\n<blockquote>\n<pre>Header always append X-Frame-Options SAMEORIGIN<\/pre>\n<\/blockquote>\n<p>This protects visitors to your web server from being redirected to malicious sites\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Clickjacking\" target=\"new\" rel=\"noopener noreferrer\">[Click here to learn more]<\/a><\/p>\n<p><strong>Disable HTTP TRACE<\/strong><\/p>\n<blockquote>\n<pre>TraceEnable off<\/pre>\n<\/blockquote>\n<p>This stops a very basic attack whereby a person can see the response of a server request.\u00a0<a href=\"http:\/\/www.cgisecurity.com\/whitehat-mirror\/WH-WhitePaper_XST_ebook.pdf\" target=\"new\" rel=\"noopener noreferrer\">[Click here to learn more]<\/a><\/p>\n<p><strong>Reduce advertised information<\/strong><\/p>\n<blockquote>\n<pre>ServerTokens Minimal\nServerSignature Off<\/pre>\n<\/blockquote>\n<p>These two settings reduce the amount of information your server advertises. Not really a major security concern but the less someone knows about your server, the better in my opinion.\u00a0<a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/mod\/core.html#serversignature\" target=\"new\" rel=\"noopener noreferrer\">[Click here to learn more]<\/a><\/p>\n<p><strong>Disable directory browsing<\/strong><\/p>\n<blockquote>\n<pre>Options -Indexes FollowSymLinks<\/pre>\n<\/blockquote>\n<p>This setting prevents the server from listing files in a directory that doesn&#8217;t have a default document such as &#8216;index.php&#8217;.\u00a0<a href=\"http:\/\/httpd.apache.org\/docs\/current\/mod\/core.html#options\" target=\"new\" rel=\"noopener noreferrer\">[Click here to learn more]<\/a><\/p>\n<h3>Test<\/h3>\n<p>There are many sites out there for testing but here are some of my favourite<\/p>\n<p><strong>Performance<\/strong><\/p>\n<p><a href=\"http:\/\/tools.pingdom.com\/fpt\/\" target=\"new\" rel=\"noopener noreferrer\">Pingdom Tools<\/a>\u00a0&#8211; Tests the load time of your page and offers recommendations<\/p>\n<p><a href=\"https:\/\/developers.google.com\/speed\/pagespeed\/insights\" target=\"new\" rel=\"noopener noreferrer\">Google PageSpeed &#8211;<\/a><\/p>\n<p><a href=\"http:\/\/loadimpact.com\/\" target=\"new\" rel=\"noopener noreferrer\">Load Impact<\/a>\u00a0&#8211; Load testing and reporting<\/p>\n<p><a href=\"http:\/\/www.blitz.io\/\" target=\"new\" rel=\"noopener noreferrer\">Blitz<\/a>\u00a0&#8211; Load testing and reporting<\/p>\n<p><strong>Security<\/strong><\/p>\n<p><a href=\"http:\/\/www.kyplex.com\/\" target=\"new\" rel=\"noopener noreferrer\">Kyplex<\/a>\u00a0&#8211; I&#8217;ve known this company since it started and their security scanner has always proved worthwhile.<\/p>\n<p><a href=\"http:\/\/www.qualys.com\/forms\/freescan\/\" target=\"new\" rel=\"noopener noreferrer\">Qualys<\/a>\u00a0&#8211; Read through their results thoughtfully because they are a bit OTT.<\/p>\n<h3>Monitor<\/h3>\n<p><a href=\"https:\/\/www.pingdom.com\/\" target=\"new\" rel=\"noopener noreferrer\">Pingdom<\/a>\u00a0&#8211; Uptime and performance monitoring<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install, Configure and Secure Environment Fresh install of\u00a0CentOS-6.3-x86_64-minimal\u00a0with the latest updates\u00a0yum update -y # uname -sro Linux 2.6.32-279.22.1.el6.x86_64 GNU\/Linux I used\u00a0nano\u00a0as the text editor, but you can just as easily use\u00a0vi yum install -y nano Prerequisites Configure Firewall Make sure you add any other rules not listed here which you are using. nano \/etc\/sysconfig\/iptables *filter [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[60],"tags":[75],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-linux","tag-install-apache-web-server-centos"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}