所有url上的nginx index.html

所有url上的nginx index.html,nginx,nginx-location,Nginx,Nginx Location,我想这样做 localhost/ | index.html localhost/category | index.html localhost/notes | index.html localhost/notes/note1 | index.html 我试着这么做,但是无数的错误阻止了我。 当我尝试使用localhost时,我看到了它 处理/index.html时重写或内部重定向循环-此错误为500 server { listen 80; serve

我想这样做

localhost/ | index.html
localhost/category | index.html
localhost/notes | index.html
localhost/notes/note1 | index.html
我试着这么做,但是无数的错误阻止了我。 当我尝试使用localhost时,我看到了它

处理/index.html时重写或内部重定向循环-此错误为500

server {
        listen       80;
        server_name  localhost;

        root C:/Users/Sergey/Desktop/xxx/angular2do;

        location / {
            if ($request_method = POST) {
                proxy_pass http://localhost:3000;
            } 

            if ($request_method = GET) {
                rewrite ^.*$ /index.html last;
            }

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        # error_page   500 502 503 504  /50x.html;
        # location = /50x.html {
        #    root   html;
        # }

    }
我知道stack在这个问题上有很多问题,但我曾经是所有这些问题的一员,并且总是捕捉到错误。

使用重写。。。位置块中的最后一个将循环重写/index.html到/index.html。你应该使用重写。。。改为休息。有关详细信息,请参阅

如果您的应用程序还需要css、js、图像等资源,您可以采用另一种方法返回静态文件(如果存在),例如:

server {
    listen       80;
    root C:/Users/Sergey/Desktop/xxx/angular2do;

    location / {
        try_files $uri @other;
    }
    location @other {
        if ($request_method != POST) { rewrite ^ /index.html last; }
        proxy_pass http://localhost:3000;
    }
}

我有一个文件-index.html,里面有很多。angular 2上的客户端代码。我曾经被打破,然后也有一个错误。。。在第二面。Nginx不会提供所有需要的文件。我现在不知道该怎么做,你有什么建议吗?我有一个错误,nginx:[emerg]named location@other只能在C:\nginx-1.11.9/conf/nginx.conf:61中位于服务器级别。使用break-nginx可以工作,但有一个问题是,它不会提供index.html中的所有文件。Angular 2有很多文件,并且会传播到许多文件夹。感谢您的帮助我的答案应该替换您现有的位置/块,以便我的答案中的两个块都位于服务器级别-请参阅更新的答案。哦,是的,但仍然存在错误。如果我使用这个代码位置/{root C:\Users\Sergey\Desktop\xxx\angular2do}所有都可以,但nginx只在我的页面上请求/-在其他页面上,例如localhost/category-否。我不明白为什么在你的建议中,angular在控制台中显示一些文件无法获取。似乎所有都可以。我拿走了现金和所有的工作。非常感谢你的比赛。