How exactly do I server static files with nginx and gunicorn for a Django app?

后端 未结 1 1263
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 14:33

Right now, I\'m trying to follow this tutorial:

http://honza.ca/2011/05/deploying-django-with-nginx-and-gunicorn

The template site loads correctly, but the i

相关标签:
1条回答
  • 2020-12-29 14:47

    Turns out I fixed my own problem... misunderstood how Nginx worked. :D

    server {
    listen 1234; //port that Nginx listens on
    server_name xxx.xx.xx.xx; #the actual IP of the server; it has a public IP address
    
    access_log /home/lilo/textImageSite/access.log;
    error_log /home/lilo/textImageSite/error.log;
    
    location /static {
        root /home/lilo/textImageSite/imageSite;
    }
    
    location / {
        proxy_pass http://127.0.0.1:8888; //the port that Gunicorn uses 
    }
    }
    

    So in my case, if I have my Gunicorn instance running on port 8888, then going to xxx.xxx.xx.x:8888/textImageSite would load the page, but without any static content. If I access it using xxx.xxx.xx.x:1234, then the page will load the static content (images, css style sheets etc). It's my first time using Gunicorn and Nginx (and first time writing a Django app too) so hopefully this will help someone who's confused :)

    0 讨论(0)
提交回复
热议问题