首页 > 解决方案 > nginx 在 Docker 容器中使用 try_files 指令

问题描述

我正在尝试从 Nginx Docker 容器中使用 try_files 指令。定位服务器的 url 是http://localhost:8080/path.

/path不存在时,该指令重写为http://localhost/notFound从 Nginx 创建 404 错误(我想这是正常的,因为 Nginx 不知道 req 首先通过容器)。有没有办法try_files重写http://localhost:8080/notFound

server {
    listen 80;
    server_name 127.0.0.1;

    try_files $uri $uri/ /notfound;

    location /page1 {       
        alias /static/page1;
    }   

    location /john {
        alias /static/demo/john;
    }

    location /notfound {
        return 404 "Sorry that file can not be found";
    }
}

标签: dockernginx

解决方案


推荐阅读