<?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; WebServer</title>
	<atom:link href="http://teclog.hattara.info/?cat=69&#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>nginxでZend Framework(rewrite)を利用する</title>
		<link>http://teclog.hattara.info/?p=293</link>
		<comments>http://teclog.hattara.info/?p=293#comments</comments>
		<pubDate>Wed, 12 Jan 2011 12:46:09 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WebServer]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=293</guid>
		<description><![CDATA[nginx + php-fpm + pecl-apcで構築されたサーバでZend Frameworkを利用する [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>nginx + php-fpm + pecl-apcで構築されたサーバでZend Frameworkを利用する際に、<br />
.htaccessが使えないことで以下のような記述ができませんでした。</p>
<blockquote><p>
## リライトエンジンを有効に。<br />
RewriteEngine On</p>
<p>## リライトの対象パスを指定<br />
RewriteBase /</p>
<p>## リライトルールを宣言（画像、CSS、Javascript）以外をindex.phpに転送する。<br />
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
</p></blockquote>
<p>通常の Apache の場合などには、.htaccessで上記のように表現できますが、<br />
nginxでは、現状各ユーザ毎のフォルダに設置して対応する方法がないようです。</p>
<p>具体的にいうと、nginx.confでincludeをサポートしているので、<br />
各ユーザ領域に設定ファイルの断片をおいて、includeさせることまではできると思われますが、<br />
そこを修正しても、読み込み直さないと反映されないので、意味がないという事になります。</p>
<p>よって、対策としては、容易に設定修正できないという難点は致し方ないとして、<br />
/etc/nginx/nginx.conf(ファイルパスは環境により異なります。)、<br />
または、includeしている　/etc/nginx/conf.d/***.confの中の該当のドメイン設定部分に<br />
以下のように追記します。</p>
<blockquote><p>
server {<br />
    listen        80;<br />
    server_name  test.example.com ;<br />
    location / {<br />
        root /home/Web;<br />
        index  index.php index.cgi index.html index.htm;<br />
        rewrite ([^(js|ico|gif|jpg|png|css)])$ index.php;<br />
    }<br />
    location ~ .php$ {<br />
        fastcgi_pass 127.0.0.1:9000;<br />
        fastcgi_index index.php;<br />
        fastcgi_param SCRIPT_FILENAME /home/Webdir/hattara.info/main/web/$fastcgi_script_name;<br />
        fastcgi_param PATH_INFO $fastcgi_script_name;<br />
        include /etc/nginx/fastcgi_params;<br />
    }<br />
}
</p></blockquote>
<p>これでとりあえず動くようになります。<br />
現状だと、逆にいえばこれしかできないような気もする。。</p>
<p>.htaccessみたいに外部で設定できるようにできたり、rewriteの設定がもう少しわかりやすいといいなぁと思うけど、<br />
これが速度とのトレードオフなのかもしれないですね。</p>
<p>ということで、rewriteとかの設定で、超はまりまくったけど、今日はこの辺で。</p>
<table cellpadding="0" cellspacing="0" border="0" style=" border:1px solid #ccc; width:170px;">
<tr style="border-style:none;">
<td style="vertical-align:top; border-style:none; padding:10px 10px 0pt;"><a href="http://px.a8.net/svt/ejp?a8mat=1NWEVP+1HL1ZU+249K+BWGDT&#038;a8ejpredirect=http%3A%2F%2Fwww.amazon.co.jp%2FNginx-Http-Server-Clement-Nedelcu%2Fdp%2F1849510865%253FSubscriptionId%253DAKIAJG4HK2PMU5Z4Q6YQ%2526tag%253Da8-affi-10084-22%2526linkCode%253Dxm2%2526camp%253D2025%2526creative%253D165953%2526creativeASIN%253D1849510865" target="_blank"><img border="0" alt="" src="http://ecx.images-amazon.com/images/I/51gax2MB8wL._SS160_.jpg" /></a></td>
</tr>
<tr style="border-style:none;">
<td style="font-size:12px; vertical-align:middle; border-style:none; padding:10px;">
<p style="padding:0; margin:0;"><a href="http://px.a8.net/svt/ejp?a8mat=1NWEVP+1HL1ZU+249K+BWGDT&#038;a8ejpredirect=http%3A%2F%2Fwww.amazon.co.jp%2FNginx-Http-Server-Clement-Nedelcu%2Fdp%2F1849510865%253FSubscriptionId%253DAKIAJG4HK2PMU5Z4Q6YQ%2526tag%253Da8-affi-10084-22%2526linkCode%253Dxm2%2526camp%253D2025%2526creative%253D165953%2526creativeASIN%253D1849510865" target="_blank">Nginx Http Server</a></p>
<p style="color:#cc0000; font-weight:bold; margin-top:10px;">新品価格<br/>￥3,964<span style="font-weight:normal;">から</span><br/><span style="font-size:10px; font-weight:normal;">(2010/12/20 19:36時点)</span></p>
</td>
</tr>
</table>
<p><img border="0" width="1" height="1" src="http://www19.a8.net/0.gif?a8mat=1NWEVP+1HL1ZU+249K+BWGDT" alt=""></p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=293</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx(VirtualDocumentRootもどき）でfastcgi(php-fpm)が動かない</title>
		<link>http://teclog.hattara.info/?p=287</link>
		<comments>http://teclog.hattara.info/?p=287#comments</comments>
		<pubDate>Mon, 20 Dec 2010 11:39:26 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[Cent]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WebServer]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=287</guid>
		<description><![CDATA[現在以下のような方法で、VirtualDocumentRootもどきを実装していますが、 PHPのSCRIPT [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>現在以下のような方法で、VirtualDocumentRootもどきを実装していますが、<br />
PHPのSCRIPT_FILENAMEが正常に取得できないようなので、調査しました。</p>
<p>【変更前】</p>
<blockquote><p>
server {<br />
    listen       80;<br />
    server_name ~^(.*)\.hoge.com$;<br />
    if (!-d /home/hoge.com/$1/web) {<br />
        rewrite . http://hoge.com/ redirect;<br />
    }</p>
<p>    location / {<br />
        index  index.php;<br />
        root /home/hoge.com/$1/web;<br />
    }</p>
<p>    location ~ \.php$ {<br />
        fastcgi_pass 127.0.0.1:9000;<br />
        fastcgi_index index.php;<br />
        fastcgi_param SCRIPT_FILENAME /home/hoge.com/$1/web/$fastcgi_script_name;<br />
        fastcgi_param PATH_INFO $fastcgi_script_name;<br />
        include /etc/nginx/fastcgi_params;<br />
    }<br />
}
</p></blockquote>
<p>上記だと、正常に動きませんでした。<br />
原因としては、以下の部分の「$1」の部分に正しい値が入らないためのようでした。</p>
<blockquote><p>
        fastcgi_param SCRIPT_FILENAME /home/hoge.com/$1/web/$fastcgi_script_name;
</p></blockquote>
<p>色々試した結果、$1を別の変数として定義してあげれば動くことを確認しました。<br />
結果、以下のような内容になりました。</p>
<p>【変更後】</p>
<blockquote><p>
server {<br />
    listen       80;<br />
    server_name ~^(.*)\.hoge.com$;<br />
    set $subdomain $1;</p>
<p>    if (!-d /home/hoge.com/$subdomain/web) {<br />
        rewrite . http://hoge.com/ redirect;<br />
    }</p>
<p>    location / {<br />
        index  index.php;<br />
        root /home/hoge.com/$subdomain/web;<br />
    }</p>
<p>    location ~ \.php$ {<br />
        fastcgi_pass 127.0.0.1:9000;<br />
        fastcgi_index index.php;<br />
        fastcgi_param SCRIPT_FILENAME /home/hoge.com/$subdomain/web/$fastcgi_script_name;<br />
        fastcgi_param PATH_INFO $fastcgi_script_name;<br />
        include /etc/nginx/fastcgi_params;<br />
    }<br />
}
</p></blockquote>
<p>とりあえず上記の記述方法で正常動作しました。よかったよかった。</p>
<table cellpadding="0" cellspacing="0" border="0" style=" border:1px solid #ccc; width:170px;">
<tr style="border-style:none;">
<td style="vertical-align:top; border-style:none; padding:10px 10px 0pt;"><a href="http://px.a8.net/svt/ejp?a8mat=1NWEVP+1HL1ZU+249K+BWGDT&#038;a8ejpredirect=http%3A%2F%2Fwww.amazon.co.jp%2FNginx-Http-Server-Clement-Nedelcu%2Fdp%2F1849510865%253FSubscriptionId%253DAKIAJG4HK2PMU5Z4Q6YQ%2526tag%253Da8-affi-10084-22%2526linkCode%253Dxm2%2526camp%253D2025%2526creative%253D165953%2526creativeASIN%253D1849510865" target="_blank"><img border="0" alt="" src="http://ecx.images-amazon.com/images/I/51gax2MB8wL._SS160_.jpg" /></a></td>
</tr>
<tr style="border-style:none;">
<td style="font-size:12px; vertical-align:middle; border-style:none; padding:10px;">
<p style="padding:0; margin:0;"><a href="http://px.a8.net/svt/ejp?a8mat=1NWEVP+1HL1ZU+249K+BWGDT&#038;a8ejpredirect=http%3A%2F%2Fwww.amazon.co.jp%2FNginx-Http-Server-Clement-Nedelcu%2Fdp%2F1849510865%253FSubscriptionId%253DAKIAJG4HK2PMU5Z4Q6YQ%2526tag%253Da8-affi-10084-22%2526linkCode%253Dxm2%2526camp%253D2025%2526creative%253D165953%2526creativeASIN%253D1849510865" target="_blank">Nginx Http Server</a></p>
<p style="color:#cc0000; font-weight:bold; margin-top:10px;">新品価格<br/>￥3,964<span style="font-weight:normal;">から</span><br/><span style="font-size:10px; font-weight:normal;">(2010/12/20 19:36時点)</span></p>
</td>
</tr>
</table>
<p><img border="0" width="1" height="1" src="http://www19.a8.net/0.gif?a8mat=1NWEVP+1HL1ZU+249K+BWGDT" alt=""></p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=287</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx(virtualhost)+php-fpmでPHPが動作しない（凡ミス編）</title>
		<link>http://teclog.hattara.info/?p=284</link>
		<comments>http://teclog.hattara.info/?p=284#comments</comments>
		<pubDate>Mon, 20 Dec 2010 10:39:17 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[Cent]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WebServer]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=284</guid>
		<description><![CDATA[Nginxでvirtualhostを切ってる状態でphp-fpmを動かそうと頑張っていたんですが、 何故か動か [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Nginxでvirtualhostを切ってる状態でphp-fpmを動かそうと頑張っていたんですが、<br />
何故か動かない。<br />
あちこちのサイトで説明されてる内容をそのままやって動かない。</p>
<p>一番下にある洋書のNginxの書籍に書いてある例をやっても動かない。<br />
なんでか悩んでいたんですが、平凡なミスであることがわかりました。</p>
<p>元々の手順としては、nginxが導入されている環境に、</p>
<p>1.PHPとPHP-FPMをyumで簡易インストールする。</p>
<blockquote><p>
yum &#8211;enablerepo=remi install php php-fpm
</p></blockquote>
<p>2.一応nginxのメインの設定にphpの設定を書いておく</p>
<blockquote><p>
vi /etc/nginx/nginx.conf</p>
<p>        # Add<br />
        location ~ .php$ {<br />
            fastcgi_pass 127.0.0.1:9000;<br />
            fastcgi_index index.php;<br />
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br />
            include /etc/nginx/fastcgi_params;<br />
        }
</p></blockquote>
<p>3.自分が作成したVirtualHost用の設定ファイル(/etc/nginx/conf.d/aaa.conf)にも追加する</p>
<blockquote><p>
vi /etc/nginx/conf.d/aaa.conf</p>
<p>server {<br />
    listen       80;<br />
    server_name  test.hoge.com;</p>
<p>    location / {<br />
        root   /home/test.hoge.com/web;<br />
        index  index.php;<br />
    }<br />
    location ~ .php$ {<br />
        fastcgi_pass 127.0.0.1:9000;<br />
        fastcgi_index index.php;<br />
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br />
        include /etc/nginx/fastcgi_params;<br />
    }<br />
}
</p></blockquote>
<p>4.php-fpmの起動ユーザーをnginxユーザにしてみる　（※必要に応じて変更するかも）</p>
<blockquote><p>
vi /etc/php-fpm.d/www.conf<br />
        user = nginx<br />
        group = nginx
</p></blockquote>
<p>5．サーバ起動時に自動起動するように起動ファイルのリンク作成</p>
<blockquote><p>
ln -s /etc/rc.d/init.d/php-fpm /etc/rc.d/rc3.d/S87php-fpm
</p></blockquote>
<p>6．サーバ起動させてみる。</p>
<blockquote><p>
/etc/rc.d/init.d/php-fpm start
</p></blockquote>
<p>という手順をしたんですが、htmlファイルは問題なく動作するのですが、phpファイルがうごかない。<br />
真っ白になったり、ダウンロードになったり・・意味がわからない。</p>
<p>結論からいうと、ドキュメントルートの設定がおかしくて、表示したいファイルに到達していなかったという事だった。<br />
どこがダメかというと、上記の「3」に問題があったようだ。</p>
<p>具体的には、</p>
<blockquote><p>
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
</p></blockquote>
<p>ここが問題で、document_root変数の下のfastcgi_script_name変数のファイルをkickするわけだが、<br />
$document_root変数の値が、どうも正しく入っていないようだ。<br />
たぶん、メインの/etc/nginx/nginx.confのrootの値を持ってたりするんじゃなかろうかと思うわけだ。</p>
<p>ということで、以下のように変更して、復旧しました。</p>
<blockquote><p>
        fastcgi_param SCRIPT_FILENAME /home/test.hoge.com/web/$fastcgi_script_name;
</p></blockquote>
<table cellpadding="0" cellspacing="0" border="0" style=" border:1px solid #ccc; width:170px;">
<tr style="border-style:none;">
<td style="vertical-align:top; border-style:none; padding:10px 10px 0pt;"><a href="http://px.a8.net/svt/ejp?a8mat=1NWEVP+1HL1ZU+249K+BWGDT&#038;a8ejpredirect=http%3A%2F%2Fwww.amazon.co.jp%2FNginx-Http-Server-Clement-Nedelcu%2Fdp%2F1849510865%253FSubscriptionId%253DAKIAJG4HK2PMU5Z4Q6YQ%2526tag%253Da8-affi-10084-22%2526linkCode%253Dxm2%2526camp%253D2025%2526creative%253D165953%2526creativeASIN%253D1849510865" target="_blank"><img border="0" alt="" src="http://ecx.images-amazon.com/images/I/51gax2MB8wL._SS160_.jpg" /></a></td>
</tr>
<tr style="border-style:none;">
<td style="font-size:12px; vertical-align:middle; border-style:none; padding:10px;">
<p style="padding:0; margin:0;"><a href="http://px.a8.net/svt/ejp?a8mat=1NWEVP+1HL1ZU+249K+BWGDT&#038;a8ejpredirect=http%3A%2F%2Fwww.amazon.co.jp%2FNginx-Http-Server-Clement-Nedelcu%2Fdp%2F1849510865%253FSubscriptionId%253DAKIAJG4HK2PMU5Z4Q6YQ%2526tag%253Da8-affi-10084-22%2526linkCode%253Dxm2%2526camp%253D2025%2526creative%253D165953%2526creativeASIN%253D1849510865" target="_blank">Nginx Http Server</a></p>
<p style="color:#cc0000; font-weight:bold; margin-top:10px;">新品価格<br/>￥3,964<span style="font-weight:normal;">から</span><br/><span style="font-size:10px; font-weight:normal;">(2010/12/20 19:36時点)</span></p>
</td>
</tr>
</table>
<p><img border="0" width="1" height="1" src="http://www19.a8.net/0.gif?a8mat=1NWEVP+1HL1ZU+249K+BWGDT" alt=""></p>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=284</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginxをyumで簡単構築（インストール,VirtualHostの設定)</title>
		<link>http://teclog.hattara.info/?p=278</link>
		<comments>http://teclog.hattara.info/?p=278#comments</comments>
		<pubDate>Wed, 01 Dec 2010 11:47:41 +0000</pubDate>
		<dc:creator><![CDATA[hattara]]></dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[WebServer]]></category>
		<category><![CDATA[未分類]]></category>

		<guid isPermaLink="false">http://teclog.hattara.info/?p=278</guid>
		<description><![CDATA[nginxのyumパッケージがfadoraのサイトに転がってるようなので、 リポジトリを追加する。(サンプルは [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>nginxのyumパッケージがfadoraのサイトに転がってるようなので、<br />
リポジトリを追加する。(サンプルは64bit版)</p>
<blockquote><p>
wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm<br />
rpm -ivh epel-release-5-4.noarch.rpm
</p></blockquote>
<p>nginxをyumで簡単インストール。</p>
<blockquote><p>
yum install nginx
</p></blockquote>
<p>とりあえずnginxを起動してみる。apacheでいうところのhttpd start</p>
<blockquote><p>
/etc/rc.d/init.d/nginx start
</p></blockquote>
<p>再起動後もちゃんと起動してくるように起動ファイルを配置する。</p>
<blockquote><p>
ln -s /etc/rc.d/init.d/nginx /etc/rc.d/rc3.d/S88nginx
</p></blockquote>
<p>VirtualHostの設定をする。<br />
Apacheでいうところの <VirtualHost>～</VirtualHost>の部分。</p>
<p>※Apacheだと、完結にはしょって書くとに以下みたいにかくやつです。</p>
<blockquote><p>
<VirtualHost *:80><br />
    ServerName hoge.com<br />
    DocumentRoot /home/hoge/web<br />
</VirtualHost>
</p></blockquote>
<p>これをnginx用に書いてみる。</p>
<blockquote><p>
vi /etc/nginx/conf.d/hoge.conf </p>
<p>server {<br />
    listen       80;<br />
    server_name  hoge.com;</p>
<p>    location / {<br />
        root   /home/hoge.com/web;<br />
        index  index.php index.pl index.cgi index.html index.htm;<br />
    }<br />
}
</p></blockquote>
<p>これで、一応うごく設定にはなってるはずです。<br />
といっても、特殊な場合以外は、VirtualHostの設定はVirtualDocumentRootで済ましたいので、<br />
以下のようにする。</p>
<p>※Apacheの場合のVirtualDocumentRoot。</p>
<blockquote><p>
<VirtualHost *:80><br />
    ServerName local<br />
    VirtualDocumentRoot /home/%2+/sub/%1/web<br />
</VirtualHost><br />
※これの場合、moge.hoge.comだと、/home/hoge.com/sub/moge/webがDocumentRootになる。
</p></blockquote>
<p>これをnginx用にかきなおす。ファイルは、さっきと同じファイルのまま。</p>
<blockquote><p>
server {<br />
    listen       80;<br />
    server_name ~^(.*)\.hoge.com$;<br />
    if (!-d /home/hoge.com/sub/$1) {<br />
        rewrite . http://hoge.com/ redirect;<br />
    }</p>
<p>    # Sets the correct root<br />
    root /home/hoge.comf/sub/$1;<br />
}
</p></blockquote>
<p>ついでにアクセスログをvirtualhostに対応したものに変更する。<br />
以下のlog_format形式を追加して、access_logのところで、mainからvhostに切り替える<br />
以下は、変更する個所、追加する個所の抜粋</p>
<blockquote><p>
vi /etc/nginx/nginx.conf</p>
<p>　　※以下を追加。<br />
    log_format  vhost &#8216;$host $remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;<br />
                      &#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;<br />
                      &#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;</p>
<p>　　※以下のように追記と修正する。<br />
    #access_log  /var/log/nginx/access.log  main;<br />
    access_log  /var/log/nginx/access.log  vhost;
</p></blockquote>
<p>これで、以下のようにaccess_logに変化が出る。</p>
<p>※変更前</p>
<blockquote><p>
192.168.0.100 &#8211; - [30/Nov/2010:20:18:02 +0900] &#8220;GET / HTTP/1.1&#8243; 200 25 &#8220;-&#8221; &#8220;Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)&#8221; &#8220;-&#8221;
</p></blockquote>
<p>※変更後</p>
<blockquote><p>
hoge.com 192.168.0.100 &#8211; - [30/Nov/2010:20:18:02 +0900] &#8220;GET / HTTP/1.1&#8243; 200 25 &#8220;-&#8221; &#8220;Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)&#8221; &#8220;-&#8221;<br />
test.hoge.com 192.168.0.100 &#8211; - [30/Nov/2010:20:18:02 +0900] &#8220;GET / HTTP/1.1&#8243; 200 25 &#8220;-&#8221; &#8220;Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)&#8221; &#8220;-&#8221;
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://teclog.hattara.info/?feed=rss2&#038;p=278</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
	</channel>
</rss>
