【发布时间】:2021-03-14 05:31:22
【问题描述】:
我在 AWS ec2 上使用 ubuntu 20.04 lts 托管 Django 应用程序。我可以在各种端口上使用 venv 运行该应用程序。我想将应用程序与 apache 绑定,以便我的用户可以仅在默认端口上使用公共 DNS 无端口访问我的应用程序。所以我已经安装了 apache2, mod_wsgi。 我的虚拟主机配置。
<VirtualHost *:80>
ServerAdmin test@example.com
DocumentRoot /var/www/html/app_folder
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /var/www/html/app_folder/static
<Directory /var/www/html/app_folder/static>
Require all granted
</Directory>
Alias /static /var/www/html/app_folder/media
<Directory /var/www/html/app_folder/media>
Require all granted
</Directory>
<Directory /var/www/html/app_folder/main_app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess app_folder python-path=/var/www/html/app_folder python-home=/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py
WSGIProcessGroup app_folder
WSGIScriptAlias / /var/www/html/app_folder/main_app/wsgi.py
</VirtualHost>
所以在配置了这个虚拟主机后,我重新启动了我的 apache2,但我在公共 dns 上什么也没有。相反,我在 /var/log/apache2/error.log 上收到以下错误日志
[Wed Dec 02 08:50:05.967958 2020] [wsgi:warn] [pid 121300] (13)Permission denied: mod_wsgi (pid=121300): Unable to stat Python home /home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Python path configuration:
PYTHONHOME = '/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py'
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/bin/python3'
sys.base_prefix = '/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py'
sys.base_exec_prefix = '/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py'
sys.executable = '/usr/bin/python3'
sys.prefix = '/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py'
sys.exec_prefix = '/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py'
sys.path = [
'/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py/lib/python38.zip',
'/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py/lib/python3.8',
'/home/ubuntu/.local/lib/python3.8/site-packages/django/__init__.py/lib/python3.8/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f0e7fa1bc40 (most recent call first):
<no Python frame>
- 那我该怎么办???
I need to upload the Django site and make it live with apache- 那么我怎样才能让服务器上线呢?
- 如何仅使用
http://public_ip查看我的网站? - 我已经阅读了很多博客,但我无法让网站与 apache 一起运行!!!
- 请查看并提出解决方案。
【问题讨论】: