docker - 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";
}
}
解决方案
推荐阅读
- ios - 如何更改 AVRoutePickerView 的元数据?
- cygwin - 在 Cygwin 中安装 dc
- c# - 反序列化嵌套的 JSON 字符串,无法访问属性
- swift - 是否可以在与 swift 中的多个键关联的字典中拥有相同的集合实例?
- c++ - 使用 sfinae 进行模板模板参数推导
- angular - 带有可排序标题的 Angular 5 材料表
- hyperledger-fabric - Hyper Fabric [fabric-sdk-go] 错误:CONNECTION_FAILED。说明:拨号连接超时
- protocol-buffers - 如何使 protobuf 不区分大小写?
- vba - Excel VBA - 如何使用 ByVal
- python - 避免大型 Pandas DataFrame 上 GroupBy 的内存问题