1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Django+NginxでDebug=Falseを設定すると、Mediaファイルが404エラーを返してくる

Last updated at Posted at 2020-05-23

Django側に問題があるかと思っていたが、実はNginx側の問題であった。

/etc/nginx/sites-available/xxxxxx のserver設定にlocationでメディアファイルのディレクトリを指定することで解決。

つまり、
location /media { 
root /home/xxxxx/xxxxxxx;
}
を追記して、以下のようにする。

server {
server_name xxxxxx.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/xxxxx/xxxxxxx;
}
location /media { 
root /home/xxxxx/xxxxxxx;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?