部署前端应用到路径的nginx配置问题?

项目部署到/app路径上,以下有两种nginx配置。

可以正确访问到应用,但会从 /app 301 到 /app/,目前不希望出现跳转。

server {

  listen 80;

  server_name ng.ct.com;

  expires 7d;

  location /app {

    root D:/code;

    index  index.html;

    try_files $uri $uri/ /app/index.html;

  }

}

不可以正确访问到应用,为什么???
如果要在这种配置下正确访问,应该还需要做什么?

server {

  listen 80;

  server_name ng.ct.com;

  expires 7d;

  location /app {

    root D:/code/app;

    index  index.html;

    try_files $uri $uri/ /index.html;

  }

}

最终目的是,可以通过 /app 访问应用,而不出现301跳转。

阅读 2.3k
2 个回答
新手上路,请多包涵

可以尝试使用端口绑定到app目录,然后用反向代理访问

try_files $uri $uri/ /app/index.html;

标红的设置去掉. 你自己都配置是先访问文件夹了.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题