Django Nginx Browser Caching Configuration

做~自己de王妃 提交于 2019-12-01 21:37:11
Wei Xu

Again, I have to answer my own question. The root problem lays on the "path".

I find the answer from @Dayo, here I quote:

You are missing the rootdirective for the images location block. Therefore, nginx will look for the files in the default location which varies by installation and since you have most likely not placed the files there, you will get a 404 Not Found error.

Answer from Dayo

Thus, I added the root path in my configuration file as following:

root /home/user/webapps/app_env/;

The whole configuration will look like this:

server {

    listen   80;
    server_name localhost;

    root /home/user/webapps/app_env/;

    client_max_body_size 4G;

    access_log /home/user/webapps/app_env/logs/nginx-access.log;
    error_log /home/user/webapps/app_env/logs/nginx-error.log;

    location /static/ {
       alias   /home/user/webapps/app_env/static/;
    }

    location /media/ {
       alias   /home/user/webapps/app_env/media/;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
       expires 365d;
    }

...
}

And everything just work nice.

I hope people with the same problem can learn from this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!