### apache2 インストール
$ sudo apt update
$ sudo apt install apache2
$ sudo ufw app list
$ sudo ufw allow ‘Apache Full’
$ sudo ufw status
$ sudo systemctl status apache2
$ hostname -I
### mod_wsgi
$ apt-get install apache2-dev
$ pip3 install mod_wsgi
### settings.py
ALLOWED_HOSTS = ['*']
$ mod_wsgi-express module-config
LoadModule wsgi_module “/home/ubuntu/.local/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so”
WSGIPythonHome “/usr”
### migrate
$ python3 manage.py makemigrations sales
$ python3 manage.py migrate
### apache設定
sudo vi /etc/apache2/sites-available/000-default.conf
LoadModule wsgi_module "/usr/lib/apache2/modules/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so" WSGIScriptAlias / /var/www/hanbai/hanbai/wsgi.py WSGIPythonHome "/usr" WSGIPythonPath "/var/www/hanbai" <VirtualHost *:80> ServerAdmin webmaster@localhost # DocumentRoot /var/www/hanbai # WSGIScriptAlias / /var/www/hanbai/hanbai/wsgi.py # WSGIPythonPath /var/www/hanbai/ <Directory /var/www/hanbai/hanbai/> <Files wsgi.py> Order deny,allow AllowOverride None require all granted </Files> </Directory> </VirtualHost>
$ sudo /etc/init.d/apache2 restart
$ /var/log/apache2/error.log
[client 59.126.236.35:46554] from django.core.wsgi import get_wsgi_application
[Wed Oct 28 23:46:17.546723 2020] [wsgi:error] [pid 10444:tid 139970643724032] [client 59.126.236.35:46554] ModuleNotFoundError: No module named ‘django’
$ pip3 freeze | grep wsgi
mod-wsgi==4.7.1
WSGIPythonPath /var/www/hanbai:/home/ubuntu/.local/lib/python3.8/site-packages
何故だ。。Djangoをインストールした場所が悪かった?
もう一回やるか。。