<?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>HattaraTecLog &#187; Apache</title>
	<atom:link href="http://teclog.hattara.info/?cat=4&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://teclog.hattara.info</link>
	<description>LinuxネタとかPHPネタとかの技術ログ</description>
	<lastBuildDate>Tue, 18 Nov 2014 12:15:20 +0000</lastBuildDate>
	<language>ja</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8</generator>
	<item>
		<title>yumでインストールしたApache2にmod_sslを足してhttpsを実現する</title>
		<link>http://teclog.hattara.info/?p=193</link>
		<comments>http://teclog.hattara.info/?p=193#comments</comments>
		<pubDate>Sat, 04 Sep 2010 14:42:35 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=193</guid>
		<description><![CDATA[ちょっと単純にhttpsを使いたいというより、別の目的のためにhttpsが必要になったので、 mod_sslを [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>ちょっと単純にhttpsを使いたいというより、別の目的のためにhttpsが必要になったので、<br />
mod_sslを利用して、httpsを実現しようと思います。</p>
<p>前提として、yumでhttpdが入っていて、正常に動作すること。とします。</p>
<p>まずは、mod_sslをyumでインストールします。<br />
※opensslがないようなら、別途インストールしてください。</p>
<blockquote><p>
　　　　yum install mod_ssl
</p></blockquote>
<p>次にApacheで利用する証明書を生成します。<br />
（お金があるなら信頼性が高い第3者機関の正式な証明書をVerisignやGlobalSignなどから購入すると良い）</p>
<p>まずは、秘密鍵を生成します。</p>
<blockquote><p>
mkdir /etc/httpd/key<br />
cd /etc/httpd/key<br />
openssl genrsa -des3 -out server.key 1024</p>
<p>すると、パスフレーズを聞かれる画面がでます。<br />
Enter pass phrase for server.key:　　aaaaa (※自分だけわかる適当なパスフレーズを打ち込んでください)<br />
Verifying &#8211; Enter pass phrase for server.key:　aaaaa (※確認画面にも同様のパスフレーズを打ち込む)
</p></blockquote>
<p>次にCSRファイルを作成します。本来はこれを第3者機関に提出し、信頼できる証明書を発行してもらいます。</p>
<blockquote><p>
openssl req -new -key server.key -out server.csr</p>
<p>するとまた質問が出るので、1個ずつ回答します。</p>
<p>(※先ほど作成したパスフレーズを打ち込みます)<br />
Enter pass phrase for server.key:　aaaaa </p>
<p>(※国を聞かれています。私は日本なのでJPです)<br />
Country Name (2 letter code) [GB]:　JP </p>
<p>(※州・県を聞かれています。福岡なのでFukuokaです)<br />
State or Province Name (full name) [Berkshire]:Fukuoka </p>
<p>（※市を聞かれています。福岡近郊なのでFukuokaにしちゃいます）<br />
Locality Name (eg, city) [Newbury]:Fukuoka　</p>
<p>（※会社名を聞かれてます。法人じゃないけど、Hattaraといれちゃう）<br />
Organization Name (eg, company) [My Company Ltd]:　Hattara </p>
<p>(※部署名を聞かれてますが、部署はないので、部署ある人だけ入力ください)<br />
Organizational Unit Name (eg, section) []: </p>
<p>(※証明書のドメイン名を入力します。)<br />
Common Name (eg, your name or your server&#8217;s hostname) []:hattara.info </p>
<p>（※メールアドレスを書かれます。いれたければ、入力してください。）<br />
Email Address []:　</p>
<p>（※パスワードの入力を求められますが、特に指定する必要なさそうなので、スルーです。）<br />
A challenge password []:　　</p>
<p>（パスワードの確認画面もスルーです。）<br />
An optional company name []:　
</p></blockquote>
<p>そして、本題の証明書を作成するわけですが、<br />
上記でも書いてある通り、貧乏な私は、第3者機関の信頼できる証明書を生成するお金がないので、<br />
自己証明（オレオレ詐欺ならぬ、オレオレ証明書）を生成します。<br />
とりあえず100年くらい持つ証明書を生成しておきます。</p>
<blockquote><p>
openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 36500</p>
<p>するとまた、見慣れた表示がでます。<br />
Enter pass phrase for server.key:　aaaaa　（※先ほど入力したパスフレーズを入力してください）
</p></blockquote>
<p>これでとりあえず自己証明書が生成完了したことになるわけですが、<br />
このままだとApacheの再起動のたびにパスフレーズを入力するはめになるので、<br />
秘密鍵からパスフレーズを削除します。</p>
<blockquote><p>
mv -i server.key server.key_backup<br />
openssl rsa -in server.key_backup -out server.key</p>
<p>すると、いつもどおりパスフレーズを聞かれるので、入力する<br />
Enter pass phrase for server.key_backup: aaaaa (※先ほど入力したパスフレーズを入力)
</p></blockquote>
<p>これで本当にSSL証明書の生成フェーズは完了。<br />
こっからは、Apache側でhttps起動してくれるように設定します。</p>
<blockquote><p>
cd /etc/httpd/conf.d/<br />
cp -p ssl.conf ssl.conf_backup　　（※一応バックアップとっておきましょう。たしなみですね。）<br />
vi ssl.conf</p>
<p>まずは、秘密鍵の設定を修正します。<br />
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key<br />
                                  ↓<br />
SSLCertificateKeyFile /etc/httpd/key/server.key</p>
<p>次に証明書ファイルの設定を修正。<br />
SSLCertificateFile /etc/pki/tls/certs/localhost.crt<br />
                                  ↓<br />
SSLCertificateFile /etc/httpd/key/server.crt</p>
<p>※一応Apacheの設定に問題がないかを確認する。<br />
/etc/rc.d/init.d/httpd configtest</p>
<p>　　結果が、「Syntax OK」なら問題なし。</p>
<p>最後にApache自体を再起動させてあげれば完了。<br />
/etc/rc.d/init.d/httpd restart
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=193</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XMLを表示できない。</title>
		<link>http://teclog.hattara.info/?p=82</link>
		<comments>http://teclog.hattara.info/?p=82#comments</comments>
		<pubDate>Mon, 27 Apr 2009 11:16:21 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[ZendFramework]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=82</guid>
		<description><![CDATA[ZendFrameworkの勉強と称して、PHPからXMLを表示しようとしてたわけですが、 XML表示ができず [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>ZendFrameworkの勉強と称して、PHPからXMLを表示しようとしてたわけですが、<br />
XML表示ができずに、以下のようなエラーが出てました。</p>
<blockquote><p>
XML パースエラー: タグの対応が間違っています。終了タグが必要です: </br><br />
URL: http://zend.hattara.info/Response/<br />
行番号: 11, 列番号: 3:<br />
</body><br />
&#8211;^
</p></blockquote>
<p>色々周りの方に確認してもらったりしたら、間違いがボロボロと。。。</p>
<ul type="square">
<li>ZendFrameworkでは、Controller部分には、phpの閉じかっこ「 ?> 」は記載しないらしい</li>
<li>XMLを表示する際には、タグの中はシングルクォートではなく、ダブルクォートを利用するらしい</li>
<li>「<?xml ～ ?>」は「<? ～ ?>」と競合するので、short_open_tagはOffにする必要があるらしい</li>
<li>charsetをUTF-8にしてるのに、ソースをEUCで記載してたので出たらしい</li>
</ul>
<p>というあたりがありました。<br />
なので、.htaccessで以下を追加したり各内容を修正したりしました。</p>
<blockquote><p>
php_value short_open_tag &#8220;Off&#8221;
</p></blockquote>
<p>この辺を全部対応して、どうにか動くようになりました。</p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=82</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendFrameworkで404エラー</title>
		<link>http://teclog.hattara.info/?p=67</link>
		<comments>http://teclog.hattara.info/?p=67#comments</comments>
		<pubDate>Mon, 09 Mar 2009 12:06:40 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[httpd.conf]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=67</guid>
		<description><![CDATA[.htaccessでmod_rewriteを使って転送してるつもりが、 404エラーになってしまう。 Apac [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>.htaccessでmod_rewriteを使って転送してるつもりが、<br />
404エラーになってしまう。</p>
<p>Apacheのエラーログ(error_log)では、「File does not exist:」が<br />
でてる状態なわけです。</p>
<p>こんな現象とちょっと戯れたので、メモしとく。</p>
<p>.htaccessの内容は以下。</p>
<p>## リライトエンジンを有効に。</p>
<blockquote><p>RewriteEngine On</p></blockquote>
<p>## リライトの対象パスを指定</p>
<blockquote><p>RewriteBase /</p></blockquote>
<p>## リライトルールを宣言（条件・アクセス先）</p>
<blockquote><p>RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php</p></blockquote>
<p>まあ、これで普通はmod_rewriteによって、該当領域にきたアクセスで<br />
RewriteRuleで指定されている画像など以外のものは、<br />
すべてindex.phpにアクセスされるようになるはずなんですね。</p>
<p>ここで大きな落とし穴がありました。<br />
.htaccessの書き方が問題なくても、<br />
そもそも.htaccessを有効にしてない場合があるわけです。</p>
<p>Apacheのhttpd.confに「AllowOverride」って項目があるわけです。<br />
これが「None」とかになってると、.htaccessが利用できないです。</p>
<p>これは、サーバ管理者にお願いする形になっちゃうんでしょうけど、<br />
修正するしかないですね。</p>
<p><a href="http://px.a8.net/svt/ejp?a8mat=U70LG+CVSQKI+5WS+BWVTD&#038;a8ejpredirect=http%3A%2F%2Fbooks.rakuten.co.jp%2Frb%2FZend-Framework%25E5%25BE%25B9%25E5%25BA%2595%25E5%2585%25A5%25E9%2596%2580-%25E5%25B1%25B1%25E7%2594%25B0%25E7%25A5%25A5%25E5%25AF%259B-9784798117126%2Fitem%2F5852116%2F" target="_blank"></p>
<p style="text-align:center">ZendFrameworkのおすすめ書籍</p>
<p><img border="0" alt="" src="http://thumbnail.image.rakuten.co.jp/@0_mall/book/cabinet/7981/79811712.jpg?_ex=200x200&#038;s=2&#038;r=1"></a><br />
<img border="0" width="1" height="1" src="http://www10.a8.net/0.gif?a8mat=U70LG+CVSQKI+5WS+BWVTD" alt=""></p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=67</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.htaccessで基本だけど忘れる事</title>
		<link>http://teclog.hattara.info/?p=55</link>
		<comments>http://teclog.hattara.info/?p=55#comments</comments>
		<pubDate>Wed, 05 Nov 2008 10:58:43 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[IP制限]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=55</guid>
		<description><![CDATA[よく.htaccessを使うわけだけども、その都度書き方をググるわけです。 面倒なんで、メモで残しておきます。 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>よく.htaccessを使うわけだけども、その都度書き方をググるわけです。<br />
面倒なんで、メモで残しておきます。</p>
<p>まず、特定ホストからのみアクセスを許可するなら、</p>
<blockquote><p>
order deny,allow<br />
deny from all<br />
allow from 192.168.0.100<br />
allow from 192.168.0.200
</p></blockquote>
<p>みたいな感じにすれば、OKですね。</p>
<p>次に、mod_rewriteで転送する場合ですが、アクセスホスト名毎に<br />
内容を分岐する(VirtualHostとか使ってない場合?)とか、<br />
コンテンツ内容によって変更する場合には、以下のような書き方でいけますね。</p>
<p>## シンボリックリンクを有効に（場合によって不要かも）</p>
<blockquote><p>
Options FollowSymLinks
</p></blockquote>
<p>## リライトのエンジンを有効に。</p>
<blockquote><p>
RewriteEngine on
</p></blockquote>
<p>## サイト名A宛でtest.phpでもtest/フォルダでもなければmainフォルダに転送</p>
<blockquote><p>
RewriteCond %{HTTP_HOST} a.com<br />
RewriteCond %{REQUEST_URI} !(^/test\.php)<br />
RewriteCond %{REQUEST_URI} !(^/test/)<br />
RewriteRule ^(.*)$ /main/ [R]
</p></blockquote>
<p>## サイトB宛で/aaa/abc.php宛のものを defフォルダに転送</p>
<blockquote><p>
RewriteCond %{HTTP_HOST} b.com<br />
RewriteCond %{REQUEST_URI} (^/aaa/abc.php)<br />
RewriteRule ^(.*)$ /def/ [R]
</p></blockquote>
<p>というような感じでできますね。<br />
あとは、これをもとの修正をいれてあげればいい感じ。</p>
<p>条件とか不要な場合には、Redirectを使えばいいですね。</p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=55</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cent4&amp;PHP5&amp;Trac&amp;Pythonの甘い罠</title>
		<link>http://teclog.hattara.info/?p=34</link>
		<comments>http://teclog.hattara.info/?p=34#comments</comments>
		<pubDate>Thu, 09 Oct 2008 12:23:43 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cent]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Trac]]></category>
		<category><![CDATA[Apache2]]></category>
		<category><![CDATA[Cent4]]></category>
		<category><![CDATA[エラーメッセージ]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=34</guid>
		<description><![CDATA[Cent4(CentOS4)系でTrac(Python&#038;Sqlite)を使う場合に、 PHP5を利用 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Cent4(CentOS4)系でTrac(Python&#038;Sqlite)を使う場合に、<br />
PHP5を利用していると、(pdo_sqlite)がconflict?するようで、<br />
TracかPhpかどちらかしか動作しなくなる。</p>
<p>具体的には、yum版のApache2とかだと、<br />
/etc/httpd/conf.d/php.conf とかで以下の記述がある場合、<br />
Tracが動かなくなる。</p>
<blockquote><p>LoadModule php5_module modules/libphp5.so</p></blockquote>
<p>具体的には、ブラウザ上では、500エラーになり、<br />
エラーログでは、以下のような出力がたくさんでる。</p>
<blockquote><p>PythonHandler trac.web.modpython_frontend: DatabaseError: unsupported file format</p></blockquote>
<p>で、上記のLoadModuleをコメントアウトすると、Phpは動かなくなるが、<br />
Tracは動くようになる。</p>
<p>ということで、PhpでSqliteを使う予定がなければ、<br />
以下のようにpdo_sqlite.iniを適当な名前にリネームしてあげればよし。</p>
<blockquote><p>mv -i /etc/php.d/pdo_sqlite.ini /etc/php.d/pdo_sqlite.ini_org</p></blockquote>
<p>その後、Apacheの再起動をお忘れなく。<br />
yum版(rpm)のApacheの場合には、</p>
<blockquote><p>/usr/sbin/apachectl restart</p></blockquote>
<p>とかでいいですね。</p>
<p>で、以下のサイトを参考にさせてもらいました。</p>
<p><a href="http://www.ryuzee.com/contents/blog/670<br />
">Ryuzee.com >> CentOS4でPHP4から5にするとTracが動かなくなる</a></p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=34</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VirtualDocumentRootの続き</title>
		<link>http://teclog.hattara.info/?p=17</link>
		<comments>http://teclog.hattara.info/?p=17#comments</comments>
		<pubDate>Wed, 10 Sep 2008 11:37:42 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=17</guid>
		<description><![CDATA[以前VirtualDocumentRootのことについて書きましたが、 そもそも何をしたかったかというと、 t [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>以前VirtualDocumentRootのことについて書きましたが、<br />
そもそも何をしたかったかというと、</p>
<p>test.com等の特定のドメインの場合には、VirtualHostを有効に。<br />
aaa.test.com のように普通のサブドメインの場合は、<br />
毎回VirtualHostを設定しなくていいようにVirtualDocumentRootを。<br />
というような入り組んだ仕組みにしたかったわけです。</p>
<p>一部特殊な設定をしているサブドメインなどがあるので、<br />
全部をVirtualDocumentRootにできなかったので、探してました。</p>
<p>で、いろいろなサイトを参考にして、結論としては、以下のようになってます。</p>
<blockquote><p>## デフォルトの設定<br />
<VirtualHost *><br />
    ServerName local<br />
    ServerAdmin hara@dedede.net<br />
    VirtualDocumentRoot /home/%2+/%1<br />
</VirtualHost></p>
<p>## 特殊な設定をする場合<br />
<VirtualHost *><br />
    ServerName aaa.test.com<br />
    ServerAdmin hara@dedede.net<br />
    DocumentRoot /home/aaa/test.com<br />
</VirtualHost><br />
　・<br />
　・<br />
　・<br />
　・</p></blockquote>
<p>この場合には、VirtualHostの中のServerNameに<br />
アクセスされているホスト名がなければ、<br />
自動で一番最初のVirtualHostの設定をよみ、<br />
VirtualDocumentRootが実行されるようです。</p>
<p>こんな感じで、VirtualHostとVirtualDocumentRootが共存できました。</p>
<p>いいっすね。<br />
こういう楽ができる技術は最高です。</p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=17</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>さっそくだけどVirtualDocumentRootについて</title>
		<link>http://teclog.hattara.info/?p=9</link>
		<comments>http://teclog.hattara.info/?p=9#comments</comments>
		<pubDate>Thu, 04 Sep 2008 11:34:04 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=9</guid>
		<description><![CDATA[Apache関係に限らず、技術系で細かい事をしようと思うと、 手元に資料がないとはまります。単純に理解が足りな [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Apache関係に限らず、技術系で細かい事をしようと思うと、<br />
手元に資料がないとはまります。単純に理解が足りないだけだけど・・</p>
<p>VirtualDocumentRootを利用して、自動でフォルダ判別したいんだけど、<br />
ドメインでフォルダほって、その下にサブドメイン名のフォルダをほる。<br />
これでわけたかったわけだけど、四苦八苦した。</p>
<p>sub.domain.comというのがあったとしたら、<br />
DocumentRootを　/home/domain.com/sub<br />
としたかったわけです。</p>
<blockquote><p>
%0 = sub.domain.com<br />
%1 = sub<br />
%2 = domain<br />
%3 = com
</p></blockquote>
<p>なわけなので、↓で試したわけです。</p>
<blockquote><p>
VirtualDocumentRoot /home/%2.%3/%1
</p></blockquote>
<p>としてみたわけですけど、apachectl configtestでエラーになりますわな。</p>
<p>エラー内容としては、</p>
<blockquote><p>
syntax error in format string
</p></blockquote>
<p>となるわけです。</p>
<p>で、焦ってしまったわけです。<br />
焦った状態で次に試したのが、↓</p>
<blockquote><p>
VirtualDocumentRoot /home/%2.3/%1
</p></blockquote>
<p>apachectlは問題なく通るわけですが、これもエラーになりますわな。<br />
エラーとしては、404エラーなわけです。</p>
<p>エラーログでは、</p>
<blockquote><p>
File does not exist: /home/m
</p></blockquote>
<p>がでます。</p>
<p>理由としては、%2の３文字目という事で、</p>
<blockquote><p>
%2 = domain
</p></blockquote>
<p>でいうところの　『m』という文字になるわけですね。</p>
<p>で、実際の処理としては、</p>
<blockquote><p>
DocumentRoot /home/m/sub
</p></blockquote>
<p>という意味わからんことになってしまってるわけです。</p>
<p>で、答えは、</p>
<blockquote><p>
VirtualDocumentRoot /home/%2+/%1
</p></blockquote>
<p>でした。<br />
%2 の後に　『+』をつけることで、%2以降全てになるようだ。<br />
httpd.confとかいじるときは、手元にApache関連の本が必要だなと実感しました。<br />
ググッても詳しいのが見当たらなかった。</p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=9</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
