LoginSignup
3
1

More than 5 years have passed since last update.

静的なファイルを含む Django のページを Nginx で表示

Posted at

静的なファイルを含まない場合のデプロイ方法
Django で作成したページを uwsgi を使って Nginx で表示

静的なファイルは、アプリの中に次のように配置されます。

├── app01
│   ├── static
│   │   └── app01
│   │       ├── app01.css
│   │       └── app01.js

静的なファイルを、/var/www/static に配置するとします。
プロジェクトを proj01 として、
設定ファイルを編集します。

proj01/setting.py
省略
STATIC_ROOT = '/var/www/static/'
省略

/var/www/static にデータを配置します。

python manage.py collectstatic

Nginx の設定変更

/etc/nginx/nginx.conf
        location / {
                include uwsgi_params;
                uwsgi_pass 127.0.0.1:3031;
        }

        location /static {
            root   /var/www;
            index  index.html index.htm;
        }

Nginx のパラメーターが正しいか確認

sudo nginx -t

uwsgi と Nginx を再起動します。

3
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
3
1