【发布时间】:2015-12-14 09:35:31
【问题描述】:
我正在使用 django 和 rest-framework 编写一个 web 服务,我使用 nginx 作为我的 web 服务器。
客户端将使用标准 REST 方法使用 API。其中一个模块允许用户上传照片,服务将名称更改为随机字符串并将其保存在:/home/myProject/files/user-content/,例如:
/home/myProject/files/user-content/bb7dfb34336d4b638e50040cf91b8d9d.png
在 API 级别,一切正常。但我希望用户能够获取他们上传的文件:/image/:filename,例如:http://mydomain/images/bb7dfb34336d4b638e50040cf91b8d9d.png
为了实现这一点,我的 nginx 配置如下:
server {
listen 80;
error_page 404 /index.html;
root /home/webworker/landingpage/Page;
index index.html index.htm;
server_name localhost;
location / {
proxy_pass http://0.0.0.0:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
location ~ ^/images/(.*)$ {
alias /home/myProject/files/user-content/$1;
access_log on;
index index.html;
autoindex off;
gzip_static on;
# expires max;
sendfile off;
add_header Cache-Control no-cache;
}
}
nginx 服务启动时没有错误,但输入我认为应该可以工作的 URL 会返回 404 not found。顺便说一句,文件对所有用户都有读取权限。
【问题讨论】:
-
你看过 nginx 日志吗?他们可能会解释什么是不工作的。
-
@Alasdair 是的,我有,没有任何帮助...
标签: django web-services nginx static http-status-code-404