簡體   English   中英

如何為Django項目設置apache2.conf文件?

[英]How to set the apache2.conf file for a django project?

我現在在aws-ec2上部署django測試項目,AMI是Ubuntu18.04,帶有Python 3.6,Django 2.1,Apache2。

該項目在/ var / www / Project下,我正在嘗試將設置添加到apache.conf中。

該項目僅由django-admin startproject Project生成,我想確保當點擊實例提供的公共IP時,它應該顯示django默認頁面。

WSGIDaemonProcess ubuntu  processes=2 threads=12 python-path=/var/www/Project
WSGIProcessGroup ubuntu
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /var/www/Project/Project/wsgi.py

<Directory /var/www/Project/Project>
    Require all granted
</Directory>

現在我收到內部服務器錯誤。

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

我以前嘗試過這個。 而且似乎只有在我將python2.7與Django 1.11一起使用時才有效。

WSGIScriptAlias / /var/www/Project/Project/wsgi.py

WSGIPythonPath /var/www/Project

<Directory /var/www/Project/Project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

我的conf文件怎么了?

我終於想出了以下解決方案。

如果您使用的是Apache2,Python2和Ubuntu18.04 LTS,則可以通過添加以下內容來更改apache2.conf文件:

WSGIScriptAlias / [path_to_wsgi.py]

WSGIPythonPath [path_to_project]

<Directory [path_to_project]>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

如果要使用最新的Django 2+版本,請更改/etc/apache2/sites-available/000-default.conf(這是HTTP端口80的設置。)(000-default.conf文件中不能包含WSGIPythonPath)虛擬主機)

<VirtualHost *:80>
ServerAdmin webmaster@localhost
Alias /static [path_to_static_folder]

<Directory [path_to_static_folder]>
Require all granted
</Directory>

<Directory [path_to_project]>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

WSGIDaemonProcess [name] python-home=[path_to_virtualenv] python-path=[path_to_project]
WSGIProcessGroup [name]
WSGIScriptAlias / [path_to_project_wsgi.py]

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM