首页 > 解决方案 > 从 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。是的,所有文件都存在于硬盘上。

标签: nginx

解决方案


推荐阅读