nginx - 从 nginx 提供 json 文件
问题描述
我正在尝试通过 nginx 提供文件。nginx 试图以错误的路径打开文件,但我不知道我做错了什么。
这是我的 nginx.conf 文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include servers/*.conf;
}
在服务器内部,我有 example.conf
server {
listen *:80;
server_name localhost;
location /hello.json {
alias /tmp/hello.json;
}
}
该文件确实存在于/tmp/hello.json
. nginx报的错误是
2020/02/18 10:42:40 [错误] 269#0: *9 open() "/usr/local/Cellar/nginx/1.17.7/html/hello.json" 失败(2:没有这样的文件或目录),客户端:127.0.0.1,服务器:localhost,请求:“GET /hello.json HTTP/1.1”,主机:“localhost”
当我尝试在浏览器中访问此文件时localhost/hello.json
。在我看来,nginx 忽略了 alias 指令。我怎样才能解决这个问题?
是的,每次修改后我都重启了nginx。是的,所有文件都存在于硬盘上。
解决方案
推荐阅读
- python - 无法从类内的函数中获取变量(python)
- javascript - Vuejs - 无法从组件访问 $root 数据
- javascript - Alpine js将“标签输入”作为数组
- java - 本地部署 Maven 工件到项目中
- javascript - Threejs,从不同的url加载mtl文件和纹理
- c++ - 不能 std::cout 隐式转换的 std::string
- url - 如何使用 Google 表格上的 IMPORT 功能导入超链接 URL?
- ems - EMS Web 应用程序不允许登录
- bash - 在 bash 脚本中使用 .env 属性
- c# - 隐藏滚动条,同时允许在 FlowLayoutPanel 中使用鼠标滚轮滚动