Nginx仅在根域时重写
我想在有两个域的地方进行 Nginx 重写:domain.com 和 domain.net,并遵循以下规则:
1)如果用户访问 http://www.domain.net/,他将被重定向到 http: //www.domain.com/ 2) 如果用户访问 http://www.domain.net/anything_else.html不会发生重写。
这是我失败的尝试:
server {
listen 80;
server_name www.domain.net domain.net;
location / {
rewrite / http://www.domain.com/ permanent;
}
}
正确的格式将不胜感激!
I'd like to do an Nginx rewrite where I have two domains: domain.com and domain.net with the following rules:
1) If a user goes to http://www.domain.net/, he will be redirected to http://www.domain.com/
2) If a user goes to http://www.domain.net/anything_else.html the rewrite will not occur.
This is my failed attempt:
server {
listen 80;
server_name www.domain.net domain.net;
location / {
rewrite / http://www.domain.com/ permanent;
}
}
The correct format would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,@blueberryfields 的答案对我来说不太有效,不得不稍微不同:
注意:使用 nginx 版本 1.1.19
Unfortunately, @blueberryfields answer didn't quite work for me, had to do it slightly different:
Note: Using nginx version 1.1.19
也许这有效:
Maybe this works: