简体   繁体   中英

How do I make my nginx load all static files from django docker app over HTTPS?

I have my nginx installed on the server and I have my Django application running inside a docker container. While my app loads fine over HTTP, it doesn't load any static files (CSS) over HTTPS. What changes should I make in nginx conf or docker app to solve this?

Since my application is in python (Django App), I collected all the static files using "python manage.py collectstatic -c" and then mounted that directory (which contains these static files - /apps/test_app/static ) on the host server running both docker and nginx.

The command I used to mount was

docker run --net=host -v /static:/apps/test_app/static -d -p 8000:8000 image_id

Here static is the directory on the host server where as /apps/test_app/static is directory inside the container.

Once this is done, I added the following lines inside the nginx.conf or ssl.conf file

location /static/ {
       # root /var/www/app/static/;
         alias /static/;
         autoindex off;
}

Followed by nginx restart and then that solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM