【问题标题】:Nginx response error 404 when processing a specific url处理特定url时Nginx响应错误404
【发布时间】:2019-12-07 17:50:31
【问题描述】:

我已经更新了我的 gem,但我丢失了我的旧 nginx 配置。我在 nginx.conf 中设置了一个新配置。我的新 Nginx 版本是 1.17.3。主页正在加载,从主页导航也是正确的。但是,如果我直接在浏览器中输入特定的 url,Nginx 会响应 404。

我不记得我错过了什么。我的 nginx.conf 文件:

events {
    worker_connections  1024;
}


http {

    upstream api.development {
    # Path to Puma SOCK file, as defined previously
        server unix:/tmp/puma.sock fail_timeout=0;
    }

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    # set client body size to 10M #
    client_max_body_size 10M;

    gzip  on;


    server {
        listen       80 default_server;
        listen [::]:80 default_server ipv6only=on;

    root   /path-to-root/app;
        index  index.html index.htm;

    # Proxy requests to backend API
        location /api {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            #proxy_set_header X-Forwarded-Proto https;
            proxy_redirect off;
            rewrite ^/api(.*) /$1 break;
            proxy_pass http://api.development;
        }
    }

    include servers/*;
}

【问题讨论】:

  • 您输入的是什么类型的网址?您正在定义根路径(我想是针对静态内容),但您没有为静态内容定义任何位置块?

标签: nginx


【解决方案1】:

我想我已经通过添加:try_files $uri $uri/ /index.html =404;

我担心的是,这条线在开发环境中工作,但是,在生产中,我还没有更新服务器,而且我没有看到我的配置文件中启用了任何 try_files。所以'我不明白这是否是我应该做的。我对 nginx 配置一点也不熟练。

【讨论】:

    猜你喜欢
    • 2013-10-17
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多