<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zarathustra Shall Speak &#187; Apache</title>
	<atom:link href="http://zarathustrashallspeak.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://zarathustrashallspeak.com</link>
	<description>And you yourself are also this Will to Power.</description>
	<lastBuildDate>Tue, 13 Jul 2010 18:35:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Apache: Multiple vhosts, one SSL vhost, and you.</title>
		<link>http://zarathustrashallspeak.com/2010/04/23/apache-multiple-vhosts-one-ssl-vhost-and-you/</link>
		<comments>http://zarathustrashallspeak.com/2010/04/23/apache-multiple-vhosts-one-ssl-vhost-and-you/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 23:36:11 +0000</pubDate>
		<dc:creator>Akairenn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://zarathustrashallspeak.com/?p=338</guid>
		<description><![CDATA[Apache has failings, oh yes.]]></description>
			<content:encoded><![CDATA[<p>Ran into a problem with a customer who&#8217;s set up with Apache virtual hosts set up on both 80 and 443.  The issue is, the only thing using SSL is a third-party application that has nothing to do with the customer&#8217;s site.</p>
<p>Apache being Apache, can do something really interesting with virtual host setups.  If you access the server by a domain that isn&#8217;t explicitly mapped to a virtual host, it&#8217;ll default to the first virtual host it encountered in its configuration files.  This is pretty neat, extremely useful, and &#8211; annoying in this case, as attempting to access the site via https is possible (since the domain is pointing to the system) but going to a place it should not be &#8211; the third-party application, which is the only SSL vhost set up.</p>
<p>Could&#8217;ve set up another vhost for SSL for the main site(s); the problem with that is Apache&#8217;s handling of SSL (IP based) and the fact that it&#8217;d require yet-another-expense &#8211; this would require a valid SSL certificate, as it&#8217;s hard to argue that going to https://mycoolsite.foo isn&#8217;t customer-facing, even if unintentional.</p>
<p>Solution is simple: quick cluster of rewrite rules to push anything not matching the domain of the third-party, SSL-using application, to non-https:</p>
<p><code>RewriteEngine On<br />
RewriteCond %{HTTP_HOST} !^crazyapplication.mycoolsite.foo$ [NC]<br />
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}</code></p>
<p>Naturally, replace crazyapplication.mycoolsite.foo with whatever.</p>
<p>So, what happens after the fact is this:  Aside from the single domain we want covered by SSL, we&#8217;re simply redirecting https to http.</p>
<p>There are other ways to do this, of course, but tactical use of mod_rewrite generally avoids the backing oneself into a corner syndrome.</p>
]]></content:encoded>
			<wfw:commentRss>http://zarathustrashallspeak.com/2010/04/23/apache-multiple-vhosts-one-ssl-vhost-and-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache: Redirect 404&#8242;d Files to a Different Domain</title>
		<link>http://zarathustrashallspeak.com/2010/03/06/apache-redirect-404d-files-to-a-different-domain/</link>
		<comments>http://zarathustrashallspeak.com/2010/03/06/apache-redirect-404d-files-to-a-different-domain/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 03:04:11 +0000</pubDate>
		<dc:creator>Akairenn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://zarathustrashallspeak.com/?p=270</guid>
		<description><![CDATA[Sorry, but I do know better than you.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll spare you the rant on Google and the horrible advice and misconceptions spewed in forums about doing this, and just give you the good stuff:</p>
<p><code>RewriteEngine on<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule ^/?(.*)$ http://TARGETDOMAIN/$1 [L]</code></p>
<p>Drop this sucker in, swap out &#8216;TARGETDOMAIN&#8217; with where you want your 404&#8242;d files redirected to.  Bah.</p>
]]></content:encoded>
			<wfw:commentRss>http://zarathustrashallspeak.com/2010/03/06/apache-redirect-404d-files-to-a-different-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Self-Signed SSL</title>
		<link>http://zarathustrashallspeak.com/2007/10/22/self-signed-ssl/</link>
		<comments>http://zarathustrashallspeak.com/2007/10/22/self-signed-ssl/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 07:04:45 +0000</pubDate>
		<dc:creator>Akairenn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://zarathustrashallspeak.com/?p=7</guid>
		<description><![CDATA[SSL isn't a security panacea, but customers have come to expect it.  And it's a good idea in many cases for internal use.  Whether you're looking at a temporary cert during development, or just want SSL without the cost on an internal site, self-signed certificates can do the job admirably.]]></description>
			<content:encoded><![CDATA[<p>A wise man once said, &#8220;There are three reasons to own a gun. To protect yourself and your family, to hunt dangerous and delicious animals, and to keep the King of England out of your face.&#8221;</p>
<p>Likewise, there are three reasons to use SSL. To protect your and your clients&#8217; passwords, to secure e-commerce transactions, and to keep Karl Rove from outing you as a CIA operative.</p>
<p>Of course, going into some sort of retirement, I&#8217;d imagine Mr. Rove won&#8217;t be committing much more high treason, but I&#8217;m sure he&#8217;ll be kicking back, playing a little shuffleboard on the weekends, and probably reading your e-mail.</p>
<p>The second fall of Rome aside, SSL is always a good idea. If there&#8217;s one thing the Internet needs, it&#8217;s more security. Of course, SSL is pissing into the wind &#8211; almost all of our efforts are pissing into the wind. We&#8217;re never going to stop users from opening &#8220;WICKED COOL SCREENSAVER!!!!!!1111.EXE&#8221; &#8211; that must not deter our course, brothers.</p>
<p>Of course, SSL costs money, doesn&#8217;t it? Screw that, hey?</p>
<p>No, it doesn&#8217;t necessarily cost a dime. If you have users that can understand very simple sentences of three to four words, words that have no more than three syllables, you can deploy self-signed SSL certificates in places that don&#8217;t justify blowing $50-$300 on a genuine signed-by-some-money-grubbing-certificate-authority certificate.</p>
<p>Let us proceed with the rocking:</p>
<p><code>yum -y install mod_ssl</code></p>
<p>This will get you mod_ssl, which should in turn get you everything you need. And possibly then some, depending on what you&#8217;re setting up. For our purposes, I&#8217;m pretending you need an SSL-secured webmail installation. I&#8217;m also assuming you&#8217;re setting up SSL for a virtual host, simply because I have virtual hosts on my box, and damned if I&#8217;m setting up another VE for you people.</p>
<p><code>openssl genrsa -des3 -out domain.name.key 4096</p>
<p>(You'll be greeted with:)</p>
<p>Enter pass phrase for domain.name.key:</code></p>
<p>Why 4096? I like big numbers. domain.name should be your domain; for example, for foo.com, use foo.com.key. This standard will continue through the rest of the commands.</p>
<p>Enter a passphrase. Make it stupidly complex, something you won&#8217;t remember and can&#8217;t type without looking at it. But be sure to store it in a safe place. Your hard drive is not a safe place. Nor is a post it not attached to your monitor.</p>
<p><code>openssl req -new -key domain.name.key -out domaine.name.csr</p>
<p>(Time for interactivity:)</p>
<p>Enter pass phrase for domain.name.key:</p>
<p>Country Name (2 letter code) [GB]:<br />
State or Province Name (full name) [Berkshire]:<br />
Locality Name (eg, city) [Newbury]:<br />
Organization Name (eg, company) [My Company Ltd]:<br />
Organizational Unit Name (eg, section) []:<br />
Common Name (eg, your name or your server's hostname) []:<br />
Email Address []:</p>
<p>A challenge password []:<br />
An optional company name []:</code></p>
<p>This is a certificate signing request, and it&#8217;s how you get a certificate &#8211; any certificate, be it self signed or not. The first prompt will be the pass phrase you created while generating domain.name.key.</p>
<p>As for the rest, since we&#8217;re self-signing, the values here don&#8217;t really matter all that much for the most part. If you&#8217;re running a respectable business and this is for some sort of internal mail server, you&#8217;ll likely want to use acceptable, &#8216;real&#8217; values. If this is for personal use, I heartily endorse the idea of insisting you&#8217;re the Queen of England.</p>
<p>A word about e-mail address &#8211; I recommend you have a &#8216;hostmaster@your.domain&#8217; set up. It&#8217;s damned useful for using for this sort of thing, as well as actual domain registration contact info. (Helps prevent you from being spammed just because you own a domain.) But really, you can use any e-mail address you wish. (Assuming it&#8217;s your e-mail address.)</p>
<p>I&#8217;ve never yet filled in a challenge password or an optional company name. Next.</p>
<p><code>cp domain.name.key domain.name.key.bak<br />
openssl rsa -in domain.name.key.bak -out domain.name.key</p>
<p>Enter pass phrase for domain.name.key.bak:</p>
<p>chmod go-rwx domain.name.key<br />
chown root:root domain.name.key</code></p>
<p>Again, this is the pass phrase from the first step. What are we doing here? We&#8217;re (*gasp*) removing the encryption from the key. Why? Because sooner or later your server is going to have a problem at three in the morning, and your hosting company, being the nice people they are, are going to try to fix it. We want them to be able to restart Apache, yes?</p>
<p>The problem with encrypted keys is, Apache won&#8217;t start without which you enter the passphrase. If your system goes down for any reason and comes back up, it&#8217;ll be stuck in boot, waiting for you to type in the passphrase. If something happens and Apache needs to be restarted, same deal. Bad thing, all around.</p>
<p>The last two commands, by the way, ensure that only the root user can read the key. Thus, if someone manages to read the key, you have bigger problems anyhow, because your system has been wtfpwned.</p>
<p><code>openssl x509 -req -days 999 -in domain.name.csr -signkey domain.name.key -out domain.name.crt</code></p>
<p>Congratulations, you now have a self-signed SSL certificate. Now it&#8217;s time for some Apache configuratin&#8217;:</p>
<p><code>cp domain.name.csr /etc/httpd/conf/ssl.csr<br />
cp domain.name.crt /etc/httpd/conf/ssl.crt<br />
cp domain.name.key /etc/httpd/conf/ssl.key</p>
<p>vi /etc/httpd/conf/ssl.conf</code></p>
<p>In this file, you want to find:</p>
<p><code>&lt;VirtualHost _default_:443&gt;</code></p>
<p>&#8230;And comment it out. Comment everything out that isn&#8217;t commented out, until you reach:</p>
<p><code>&lt;/VirtualHost&gt;</code></p>
<p>&#8230;And comment that out, too. Then save and exit.</p>
<p><code>vi /etc/httpd/conf/httpd.conf</code></p>
<p>Time to set up your real virtual host entry. Here&#8217;s an example of one:</p>
<p><code>&lt;VirtualHost IPADDRESS:443&gt;<br />
ServerName HOSTNAME<br />
DocumentRoot /path/to/html<br />
ErrorLog /path/to/error_log<br />
CustomLog /path/to/access_log combined<br />
SSLCertificateFile /etc/httpd/conf/ssl.crt/domain.name.crt<br />
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/domain.name.key<br />
SSLEngine on<br />
&lt;/VirtualHost&gt;</code></p>
<p>IP address is naturally the IP address of your system, or at least the IP address the domain you&#8217;re using is pointing at. ServerName is the hostname, and should be what you listed for &#8216;Common Name&#8217; on the certificate signing request. The rest, I leave to you. Anyhow, once done, restart Apache:</p>
<p><code>/etc/init.d/httpd restart</code></p>
<p>Open your web browser, go to your domain, using https instead of http. You should get a little window. The message varies with your browser, but should basically say, &#8216;Oh noes, I don&#8217;t recognize this Certificate Authority!11111111111&#8242;</p>
<p>If you want, examine the details, but unless you did something really wrong, it should be your certificate. FireFox, at least, will allow you to accept the certificate permanantly; which if you&#8217;re setting up an internal site or something for a company, might be a good idea to click. (Less confused users.)</p>
<p>No such option with IE &#8211; at least not IE6. Such is life, but you now have SSL, even if Microsoft doesn&#8217;t recognize you as a certificate authority.</p>
<p>It&#8217;s okay; after all, no one respects their authority, either.</p>
<p>So what&#8217;s next? You now have SSL on a domain. You can set up all sorts of crazy things, or you can do something useful and set up webmail or something. The sky is the limit, or some such.</p>
]]></content:encoded>
			<wfw:commentRss>http://zarathustrashallspeak.com/2007/10/22/self-signed-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
