Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/tr/docs/http/converting_rewrite_rules.xml
1 views
1
<!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
2
3
<article name="rewrite kurallarının çevirisi"
4
link="/tr/docs/http/converting_rewrite_rules.html"
5
lang="tr">
6
7
<section name="Ana siteye yönlendirme">
8
9
<para>
10
Paylaşımlı hosting kullananlar genelde her şeyi, sadece Apache&rsquo;nin .htaccess dosyalarını yapılandırarak kullanırlar. Bu dosyada bulunan kuralların çevirisine örnek olarak:
11
12
<programlisting>
13
RewriteCond %{HTTP_HOST} example.org
14
RewriteRule (.*) http://www.example.org$1
15
</programlisting>
16
17
kuralı, nginx içerisinde şu şekilde yapılıyor:
18
19
<programlisting>
20
server {
21
listen 80;
22
server_name www.example.org example.org;
23
if ($http_host = example.org) {
24
rewrite (.*) http://www.example.org$1;
25
}
26
...
27
}
28
</programlisting>
29
</para>
30
31
<para>
32
Bu yanlış, kullanışsız ve etkisiz bir yoldur. Doğru olan ayrı bir sunucu tanımlaması yapmaktır:
33
34
<programlisting>
35
server {
36
listen 80;
37
server_name example.org;
38
rewrite ^ http://www.example.org$request_uri?;
39
}
40
41
server {
42
listen 80;
43
server_name www.example.org;
44
...
45
}
46
</programlisting>
47
</para>
48
49
</section>
50
51
52
<section>
53
54
<para>
55
Diğer bir örnek ile aşağıdaki geri kalmış mantık yerine (<literal>example.com</literal> olmayan her şey ve <literal>www.example.com</literal> olmayan her şey):
56
57
<programlisting>
58
RewriteCond %{HTTP_HOST} !example.com
59
RewriteCond %{HTTP_HOST} !www.example.com
60
RewriteRule (.*) http://www.example.com$1
61
</programlisting>
62
63
sadece <literal>example.com</literal>, <literal>www.example.com</literal> ve diğer her şeyi ayrı ayrı tanımlamalısınız:
64
65
<programlisting>
66
server {
67
listen 80;
68
server_name example.com www.example.com;
69
...
70
}
71
72
server {
73
listen 80 default_server;
74
server_name _;
75
rewrite ^ http://example.com$request_uri?;
76
}
77
</programlisting>
78
</para>
79
80
</section>
81
82
83
<section id="converting_mongrel_rules"
84
name="Mongrel kurallarının çevirisi">
85
86
<para>
87
Tipik Mongrel kuralları:
88
89
<programlisting>
90
DocumentRoot /var/www/myapp.com/current/public
91
92
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
93
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
94
RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]
95
96
RewriteCond %{REQUEST_FILENAME} -f
97
RewriteRule ^(.*)$ $1 [QSA,L]
98
99
RewriteCond %{REQUEST_FILENAME}/index.html -f
100
RewriteRule ^(.*)$ $1/index.html [QSA,L]
101
102
RewriteCond %{REQUEST_FILENAME}.html -f
103
RewriteRule ^(.*)$ $1/index.html [QSA,L]
104
105
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
106
</programlisting>
107
108
şu şekilde dönüştürülmelidir:
109
110
<programlisting>
111
location / {
112
root /var/www/myapp.com/current/public;
113
114
try_files /system/maintenance.html
115
$uri $uri/index.html $uri.html
116
@mongrel;
117
}
118
119
location @mongrel {
120
proxy_pass http://mongrel;
121
}
122
</programlisting>
123
</para>
124
125
</section>
126
127
</article>
128
129