html5Mode 中的 AngularJS 1.0.7 刷新页面时出现 404 错误 [英] AngularJS 1.0.7 in html5Mode get 404 error when refresh page

查看:31
本文介绍了html5Mode 中的 AngularJS 1.0.7 刷新页面时出现 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些关于这个主题的帖子.我已经阅读了其中的大部分内容,但我认为我不够熟练,无法理解我应该做什么.

I know there are some posts about this topic. I have read most of them, but I think I´m not skilled enough to understand what should I do.

我有一个 AngularJS 1.0.7 网络应用程序.我刚刚将它配置为 html5Mode 来美化我的 URL.我的 URL 现在看起来不错,但我遇到了一个在更改之前没有的新问题.当我第一次加载我的索引页面时,我可以毫无问题地刷新它.但是,如果我导航到示例/about 中的其他页面,然后刷新页面,则会收到 404 错误.

I have an AngularJS 1.0.7 web application. I have just configured it to html5Mode to prettify my URLs. My URLs looks nice now, but I got a new problem I hadn´t before the change. When I first load my index page, I can refresh it without problem. However, if I navigate to some other page in example /about and then I refresh the page I get a 404 Error.

例如在这篇文章中:使用 AngularJS HTML5 模式重新加载页面会给出错误的 GET 请求 我读过我应该将服务器端的 url 重写到我的入口点,我猜是 index.html,但我不知道这是什么手段和方法.

For example in this post: Reloading the page gives wrong GET request with AngularJS HTML5 mode I have read that I should rewrite my urls in server side to my entry point, I guess index.html, but I don´t have any idea about what this means and how to do it.

有人能提供更详细和更实际的例子吗?

Would anybody be so kind to provide a bit more detailed and practical example?

当他们谈论服务器时,他们是什么意思?我有一个运行在 Nginx 服务器上的 Angular 应用程序,它将请求发送到运行在 Puma 服务器上的 Rails API.

What does they mean when they talk about the server? I have an Angular application running on an Nginx server that sends requests to a Rails API that runs on a Puma server.

推荐答案

所以这个想法是强制 Nginx 将所有 htpp 请求指向 index.html,并让 Angular 在您的应用程序中进行路由.

So the idea is to force Nginx to point all htpp requests to index.html and let the Angular do the routing in your application.

您没有发布任何配置,所以这是最基本的:

You didn`t post any configuration so here is the most basic:

server {
 listen 80;
 server_name foobar.com www.foobar.com;
 index index.html;
 root /var/www/mysite;

location / {
  try_files $uri$args $uri$args/ index.html;
 }
}

这篇关于html5Mode 中的 AngularJS 1.0.7 刷新页面时出现 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆