我正在嘗試使用 apache2 在 linux ubuntu 服務器上部署我的 django 專案。當我不使用虛擬 venv 時,我可以正確部署它。我重建了我的虛擬機并做了同樣的事情,但是使用了虛擬環境并且它不起作用。
當我訪問我的網站網址時,它給了我這個錯誤 Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
這是我的 /etc/apache2/sites-available/mysite.conf
<VirtualHost *:80>
ServerName MYIPSERVER
ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined
WSGIDaemonProcess mysite processes=2 threads=25 python-path=/var/www/mysite/venv/lib/python3.10/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /robots.txt /var/www/mysite/static/robots.txt
Alias /favicon.ico /var/www/mysite/static/favicon.ico
Alias /static/ /var/www/mysite/static/
Alias /static/ /var/www/mysite/media/
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite/static>
Require all granted
</Directory>
<Directory /var/www/mysite/media>
Require all granted
</Directory>
</VirtualHost>
在沒有 venv 之前,WSGIDaemonProcess 是這樣設定的
WSGIDaemonProcess mysite processes=2 threads=25 python-path=/var/www/mysite但它不起作用,所以我為此改變了它:
WSGIDaemonProcess mysite processes=2 threads=25 python-path=/var/www/mysite/venv/lib/python3.10/site-packages
它仍然無法正常作業。我不確定問題出在哪里。我的專案檔案夾位于 /var/www
uj5u.com熱心網友回復:
您需要將python-home引數設定為包含您的 virtualenv 的檔案夾,并將python-path引數設定為包含您的專案的檔案夾。請參閱https://docs.djangoproject.com/en/stable/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode
WSGIDaemonProcess example.com python-home=/path/to/venv python-path=/path/to/mysite.com
WSGIProcessGroup example.com
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/522100.html
