简体   繁体   English

Nginx:怎么写?

[英]Nginx: how to do rewrite?

My website have three different pages: 我的网站有三个不同的页面:

www.abc.com/
www.abc.com/node
www.abc.com/memeber

If I type www.abc.com in the browser,it goes to www.abc.com/ , how can I change it to www.abc.com/node when I type www.abc.com and keep the www.abc.com/memeber normal as usual? 如果在浏览器中输入www.abc.com ,它将转到www.abc.com/ ,当我输入www.abc.com并保留www.abc.com/memeber时如何将其更改为www.abc.com/node www.abc.com/memeber正常照常吗?

Just adding a small note, use return instead of rewrite for redirects, check nginx pitfalls 只需添加一个小注释,使用return而不是rewrite进行重定向, 检查nginx陷阱

location = / {
  return 301 $scheme://$server_name/node
}
location / {
  # normal location handling, using try_files for example
}

Following worked for me provided I was only serving static files. 在我仅提供静态文件的情况下,以下对我有用的工作。

server {
    listen 80;
    server_name www.abc.com;
    root /var/www/abc;

    if ($request_uri = '/') {
        rewrite ^ /node break;
    }
}
location = / {
  rewrite ^ /node;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM