comparison xml/ja/docs/http/converting_rewrite_rules.xml @ 0:61e04fc01027

Initial import of the nginx.org website.
author Ruslan Ermilov <ru@nginx.com>
date Thu, 11 Aug 2011 12:19:13 +0000
parents
children 9d544687d02c
comparison
equal deleted inserted replaced
-1:000000000000 0:61e04fc01027
1 <!DOCTYPE digest SYSTEM "../../../../dtd/article.dtd">
2
3 <article title="rewrite ルールのコンバート"
4 link="/ja/docs/http/converting_rewrite_rules.html"
5 lang="ja">
6
7 <section title="メインサイトへのリダイレクト">
8
9 <para>
10 共有のホスティングで Apache の .htaccess ファイル<i>のみ</i>で<i>すべて</i>を設定してきたのなら、次のようにルールをコンバートします:
11
12 <programlisting>
13 RewriteCond %{HTTP_HOST} nginx.org
14 RewriteRule (.*) http://www.nginx.org$1
15 </programlisting>
16
17 上記は下記のようになります:
18
19 <programlisting>
20 server {
21 listen 80;
22 server_name www.nginx.org nginx.org;
23 if ($http_host = nginx.org) {
24 rewrite (.*) http://www.nginx.org$1;
25 }
26 ...
27 }
28 </programlisting>
29 </para>
30
31 <para>
32 これは間違っていて面倒で非効率的な方法です。正しい方法は <url>nginx.org</url> 用に別のサーバを定義します:
33
34 <programlisting>
35 server {
36 listen 80;
37 server_name nginx.org;
38 rewrite ^ http://www.nginx.org$request_uri?;
39 }
40
41 server {
42 listen 80;
43 server_name www.nginx.org;
44 ...
45 }
46 </programlisting>
47 </para>
48
49 </section>
50
51
52 <section>
53
54 <para>
55 別の例として、<url>nginx.com</url> 以外と <url>www.nginx.com</url> 以外のすべて、という後方ロジックの代わりの例です:
56
57 <programlisting>
58 RewriteCond %{HTTP_HOST} !nginx.com
59 RewriteCond %{HTTP_HOST} !www.nginx.com
60 RewriteRule (.*) http://www.nginx.com$1
61 </programlisting>
62
63 この場合、単に <url>nginx.com</url>、<url>www.nginx.com</url>、そしてそれ以外を定義します:
64
65
66 <programlisting>
67 server {
68 listen 80;
69 server_name nginx.org www.nginx.org;
70 ...
71 }
72
73 server {
74 listen 80 default_server;
75 server_name _;
76 rewrite ^ http://nginx.org$request_uri?;
77 }
78 </programlisting>
79 </para>
80
81 </section>
82
83
84 <section name="converting_mongrel_rules"
85 title="Mongrel ルールのコンバート">
86
87 <para>
88 典型的な Mongrel のルール:
89
90 <programlisting>
91 DocumentRoot /var/www/myapp.com/current/public
92
93 RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
94 RewriteCond %{SCRIPT_FILENAME} !maintenance.html
95 RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]
96
97 RewriteCond %{REQUEST_FILENAME} -f
98 RewriteRule ^(.*)$ $1 [QSA,L]
99
100 RewriteCond %{REQUEST_FILENAME}/index.html -f
101 RewriteRule ^(.*)$ $1/index.html [QSA,L]
102
103 RewriteCond %{REQUEST_FILENAME}.html -f
104 RewriteRule ^(.*)$ $1/index.html [QSA,L]
105
106 RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
107 </programlisting>
108
109 上記は次のようにコンバートされます
110
111 <programlisting>
112 location / {
113 root /var/www/myapp.com/current/public;
114
115 try_files /system/maintenance.html
116 $uri $uri/index.html $uri.html
117 @mongrel;
118 }
119
120 location @mongrel {
121 proxy_pass http://mongrel;
122 }
123 </programlisting>
124 </para>
125
126 </section>
127
128 </article>