nginx - Nginx 目录列表仅用于子路径
问题描述
我试图将我的子路径作为仅在 Nginx 中列出的目录,但是它返回 404。
假设我有以下配置http://file.example.com/test
:
server {
listen 80;
server_name file.example.com;
location /test/ {
root /var/www/abc/def/;
autoindex on;
autoindex_exact_size off;
autoindex_format html;
autoindex_localtime on;
}
}
我没有指定/
部分,是不是上面导致的问题不起作用?我错过了什么?
解决方案
将位置更改为location /test
将所有文件复制到/var/www/abc/def/test
文件夹,因为您正在使用 location 指令和 root 指令。在您的情况下,当 Nginx 搜索静态文件时,它将使用根路径/var/www/abc/def
并附加位置路径/test
。
或者按照@RichardSmith 的建议使用别名。
推荐阅读
- python - 如何使用 Google Sheets API 在数据透视表中按值“总计”排序
- java - 使用 JPA 升级 Spring Boot 2 无法实例化 [com.zaxxer.hikari.HikariDataSource]
- javascript - 如何简化嵌套的 setState();如何使对象通用?(太多不同的字段/状态键)
- branch - 如何使用 GraphQL 获取 GitHub 分支名称
- javascript - 在 API 调用上使用 Angular 6 创建动态更新图
- javascript - 如何从搜索结果中删除过去的数据并仅显示当前数据
- c - 为什么不调用 fgets?
- vba - 创建范围排除中间列
- python-3.x - ImportError:/home/u8400/.local/lib/python3.6/site-packages/dlib.cpython-36m-x86_64-linux-gnu.so:未定义符号:cblas_dtrs
- javascript - 是否可以将车把表达式值传递给子表达式?