nginx serving Django static media | 502 bad gateway

后端 未结 5 1354
暗喜
暗喜 2021-02-11 09:14

I\'m trying to serve Django static media through nginx, Here\'s my nginx.conf

server {
    listen       7777;
    listen       localhost:7777;
    server_name  e         


        
5条回答
  •  攒了一身酷
    2021-02-11 10:03

     502 bad gateway
    

    is because apache has a problem (not restarted or something like that). You can check the apache server logs for info.

    The problem is your /sites/mysite/staticmedia/ is being passed to apache and not served by nginx itself.

    Your nginx media part has to be like this:

    location /staticmedia/ {
        root /sites/mysite/;
        expires max;
        autoindex on
      }
    

    This will access /sites/mysite/staticmedia/ on the filesystem.

    That is, the path of location specified with location is a considered to be the part of the file system too. (I don't think this is good way either; but this is how nginx does it.)

    You can leave the autoindex on, to help you during debug.

提交回复
热议问题