我需要一个nginx的重写规则重写来自:nginx的子域重写
http://some-keyword.example.com
到www.example.com/keyword.php?keyword=$some-keyword
,而无需在前面www
域还是重写为www.example.com
和www
未作为关键字。
请你能帮我解决这个问题,怎么写这两条规则?
我需要一个nginx的重写规则重写来自:nginx的子域重写
http://some-keyword.example.com
到www.example.com/keyword.php?keyword=$some-keyword
,而无需在前面www
域还是重写为www.example.com
和www
未作为关键字。
请你能帮我解决这个问题,怎么写这两条规则?
如果你的意思是重定向,则:
server {
server_name ~^(.*)\.example\.com$ ;
rewrite^http://www.example.com/keyword.php?keyword=$1 redirect;
}
在重写随后的情况下根本就
server {
server_name example.com ~^(.*)\.example\.com$ ;
rewrite^/keyword.php?keyword=$1 break;
# location /keyword.php {
# ....
# }
}
即使问题是关于重写,您的示例并不排除“www”应该像它应该。你需要为这个添加一个负面的lookahead构造:'^((?!www \。)。*)\。example \ .com $' – conny 2010-03-23 10:56:23
配置应该没问题,因为Nginx具有服务器搜索顺序,正式名称(www.example.com)在正则表达式之前。 – 2010-03-24 10:25:09
我有类似的问题,但这个解决方案似乎并没有重写主机。在OP中,他要求服务器在规则完成时处理www.example.com/keyword.php?keyword=$1,但这似乎只重写路径和查询。有没有办法在内部重写主机?我只看到了使用重定向的例子,我的所有实验都失败了。谢谢。 – 2011-01-28 07:30:28
rewrite ^/list-c-([0-9]+)-k-(.+)-o-1\.html$ /index.php?module=Default&action=List&c=$1&k=$2&o=1 last;
rewrite ^/list-c-([0-9]+)-k-(.+)-o-1-p-(.+)\.html$ /index.php?module=Default&action=List&c=$1&k=$2&o=1&p=$3 last;
rewrite ^/list-c-([0-9]+)-k-(.+)-o-1-price-(.+)\.html$ /index.php?module=Default&action=List&c=$1&k=$2&o=1&price=$3 last;
rewrite ^/list-c-([0-9]+)-k-(.+)-o-(.+)-p-1\.html$ /index.php?module=Default&action=List&c=$1&k=$2&o=$3&p=1 last;
rewrite ^/list-c-([0-9]+)-k-(.+)-o-(.+)-p-(.+)\.html$ /index.php?module=Default&action=List&c=$1&k=$2&o=$3&p=$4 last;
如果有可能我只创造100台服务器(虚拟主机)这是正常的domain.com
/www.domain.com
然后用conf来重写其余的给他们
server {
server_name domain.com www.domain.com;
# normal handling for files
}
server {
server_name ~(?<subdomain>[^\.]*).domain.com;
location/{
try_files keyword.php?keyword=$subdomain =404;
}
}
请告诉我,如果我错过了什么。
你说重写(如在服务器端,代理重写),但它听起来像你的意思是重定向?在重定向时,对用户可见的URL发生更改。在代理重写时,这一切都发生在服务器端,用户不可见。 – conny 2010-03-23 09:58:42
我的意思是重写,用户应该看到的是http://keyword.example.com Conny – ivan73 2010-03-23 10:49:32