nginx配置自动跳转

时间:2023-03-08 17:51:18

希望实现的效果是,用户只要访问域名,自动跳转到index.html页面

原本配置为:

  1. location / {
  2. root   /users/apple/git_local/YAE/YAE/frontend;
  3. index  /portal/nail/index.html;
  4. }
location / {
root /users/apple/git_local/YAE/YAE/frontend;
index /portal/nail/index.html;
}

这样虽然可以达到目的,但是浏览器里的URL还是www.xxx.com。如果页面上有链接使用相对路径,就会发生404错误,所以需要配置为:

  1. rewrite ^/(index.html)?$ portal/nail/index.html redirect;
  2. location / {
  3. root   /users/apple/git_local/YAE/YAE/frontend;
  4. index  /portal/nail/index.html;
  5. }
rewrite ^/(index.html)?$ portal/nail/index.html redirect;

location / {

root /users/apple/git_local/YAE/YAE/frontend;

index /portal/nail/index.html;

}

浏览器的URL会变成www.xxx.com/portal/nail/index.html,这样相对路径就能正常访问了

<div id="share_weibo">分享到:
<a data-type="sina" href="javascript:;" title="分享到新浪微博"><img src="/images/sina.jpg"></a>
<a data-type="qq" href="javascript:;" title="分享到腾讯微博"><img src="/images/tec.jpg"></a>
</div>
  <li class="last"><a href="https://www.iteye.com/wiki/blog/2070350" target="_blank" class="more">查看更多</a></li>
</ul>
评论