0
1

nginx プロキシサーバ

Last updated at Posted at 2023-12-30

nginx プロキシサーバにDjangoをバインドする

Django のアプリケーションはエラー無く、python3 manage.py runserver が起動するものとする。
つまり、nginx 側の設定を紹介することにします。

環境

Ubuntu 22.04.02 LTS
nginx 1.18.0
Python 3.10.12
Django 5.0

/etc/nginx/nginx.conf

#実際に記入するときには、{}を外して書いてください。
#以下のupstreamとserverの記述を追加してください。

http {
    upstream {xxx.mydomain.net} {
        server 127.0.0.1:8000;
    }

    server {
        listen 80;
        server_name {xxx.mydomain.net};
        root /home/{ユーザー名}/{Django-App};

        location / {
            proxy_pass http://{xxx.mydomain.net};
        }
    }
}

次に、settings.pyです。

settings.py
ALLOWED_HOSTS = ['*']

もしくは

#実際に記入するときには、{}を外して書いてください。

ALLOWED_HOSTS = ['{xxx.mydomain.net}']

#ワイルドカードでも、ホスト名が決まっていればそれを書いても動きます。
#無いと正常に動きません

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