本文将以一些实例简单对Nginx的一些常用的URL重写方法做个简要的介绍。废话这里也不多说了哈,下面就转入正题。
1. 在 Apache 中的写法RewriteCond %{HTTP_HOST} nginx.org
RewriteRule (.*) http://www.nginx.org$1
在 Nginx 可以对应写成:server {
listen 80;
server_name www.nginx.org nginx.org;
if ($http_host = nginx.org) {
rewrite (.*) http://www.nginx.org$1;
}
...
}
但 Nginx 作者更建议的方法是:server {
listen 80;
server_name nginx.org;
rewrite ^ http://www.nginx.org$request_uri?;
}
server {
listen 80;
server_name www.nginx.org;
...
}
location / {
root /var/www/myapp.com/current/public;
try_files /system/maintenance.html
$uri $uri/index.html $uri.html
@mongrel;
}
location @mongrel {
proxy_pass http://mongrel;
}
总体感觉这个就比Apache 的要简化多了。如果你需要了解更多关于Nginx URL规则重写的知识,可以关注本博客相关分类或标签。
最后更新于 2011-06-11 00:07:53 并被添加「linux apache nginx rewrite」标签,已有 13647 位童鞋阅读过。
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处
相关文章