首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >刷新页面后JS单页站点出现404错误

刷新页面后JS单页站点出现404错误
EN

Stack Overflow用户
提问于 2020-04-10 21:59:57
回答 2查看 62关注 0票数 0

我有nginx和JS单页网站。刷新页面"mysite.com/user“后出现404错误。它的页面在第一次使用时可以工作,但在页面刷新后,nginx返回404错误。

代码语言:javascript
运行
复制
[error] 30149#0: *45 open() "/var/www/users" failed (2: No such file or directory), client: , server: mysite.com, request: "GET /users HTTP/1.1", host: "mysite.com"`

请帮帮忙。

站点会议

代码语言:javascript
运行
复制
server {
    listen       80;
    server_name  mysite.com;
    root    /var/www/;

    location / {
        try_files $uri $uri/ /index.html;
 if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '$http_origin';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';

        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain; charset=utf-8';
        add_header 'Content-Length' 0;
        return 204;
     }
     if ($request_method = 'POST') {
        add_header 'Access-Control-Allow-Origin' '$http_origin';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
     }
     if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '$http_origin';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
     }
    }

    location /static/ {
        add_header Cache-Control max-age=31536000;
    }

    location /index.html {
        add_header Cache-Control no-cache;
    }

    location /config.json {
        add_header Cache-Control no-cache;
    }

    location /api {
        proxy_pass http://backend;
    }


    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

我不明白为什么它是工作(

EN

Stack Overflow用户

发布于 2020-04-10 22:20:42

您需要添加:

代码语言:javascript
运行
复制
location / {
    try_files $uri $uri/ =404;
}

有关更多信息,请访问check

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61141879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档