#やりたいこと
uWSGIを使用してdjangoをスタートしたい
#ハマっていること
pipenv run uwsgi --http :8000 --module project.project.wsgi
を実行した際エラー?かよくわかりませんが下記が出力される
sh
1/django# pipenv run uwsgi --http :8000 --module project.project.wsgi 2*** Starting uWSGI 2.0.19.1 (64bit) on [Thu Apr 1 14:43:04 2021] *** 3compiled with version: 8.3.0 on 01 April 2021 14:41:46 4os: Linux-5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 5nodename: 0db005f1f7dc 6machine: x86_64 7clock source: unix 8pcre jit disabled 9detected number of CPU cores: 2 10current working directory: /django 11detected binary path: /root/.local/share/virtualenvs/django-tLoTjnL9/bin/uwsgi 12uWSGI running as root, you can use --uid/--gid/--chroot options 13*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 14*** WARNING: you are running uWSGI without its master process manager *** 15your memory page size is 4096 bytes 16detected max file descriptor number: 1048576 17lock engine: pthread robust mutexes 18thunder lock: disabled (you can enable it with --thunder-lock) 19uWSGI http bound on :8000 fd 4 20spawned uWSGI http 1 (pid: 13) 21uwsgi socket 0 bound to TCP address 127.0.0.1:38883 (port auto-assigned) fd 3 22uWSGI running as root, you can use --uid/--gid/--chroot options 23*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 24Python version: 3.9.2 (default, Mar 31 2021, 12:21:33) [GCC 8.3.0] 25*** Python threads support is disabled. You can enable it with --enable-threads *** 26Python main interpreter initialized at 0x560431aadf00 27uWSGI running as root, you can use --uid/--gid/--chroot options 28*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 29your server socket listen backlog is limited to 100 connections 30your mercy for graceful operations on workers is 60 seconds 31mapped 72904 bytes (71 KB) for 1 cores 32*** Operational MODE: single process *** 33WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x560431aadf00 pid: 8 (default app) 34uWSGI running as root, you can use --uid/--gid/--chroot options 35*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 36*** uWSGI is running in multiple interpreter mode *** 37spawned uWSGI worker 1 (and the only) (pid: 8, cores: 1)
上記が出ている際にポートを確認したが開いている様子がない
sh
1$ curl localhost:8000 2curl: (7) Failed to connect to localhost port 8000: Connection refused
##プロジェクト構造
/django$ tree . ├── Dockerfile ├── Pipfile ├── Pipfile.lock └── project ├── db.sqlite3 ├── manage.py ├── project │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── trades ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ └── __init__.py ├── models.py ├── tests.py └── views.py
django/project/project/wsgi.py
はstartproject時のまま使用していますが
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.project.settings')
のみプロジェクト構造に合わせています
やったこと
!!! no internal routing support, rebuild with pcre support !!!
の一文で検索すると下記ページが出てきたため、
rebuild uwsgi with pcre support - Stack Overflow
sudo apt-get install libpcre3 libpcre3-dev
を行なったのち
pipenv installにてuwsgiをインストールしています
Dockerfile
1FROM python:slim 2 3WORKDIR /django 4 5COPY Pipfile Pipfile.lock /django/ 6 7RUN apt-get update && apt-get install gcc libpcre3 libpcre3-dev -y 8 9RUN python -m pip install --upgrade pip \ 10 && python -m pip install pipenv \ 11 && pipenv install
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。