我正在写一个使用django和rest-framework的web服务,并且使用nginx作为我的web服务器。nginx:提供别名url的静态内容
客户端将使用标准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
。 BTW文件具有所有用户的读取权限。
你看过nginx日志 - 他们可能会解释什么是不工作。 – Alasdair
@Alasdair是的,我有,没有什么帮助... –