当我尝试通过apache服务器访问lan ip地址上的django时,我得到了apache2的默认页面。我也在运行django getBytes()
命令,并尝试使用python manage.py runsever
访问。但它仍显示apache的默认页面。
如何使用apache访问django?
192.168.10.11
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/five/NewsDesk/server
WSGIScriptAlias / /home/five/NewsDesk/server/server/wsgi.py
# adjust the following line to match your Python path
WSGIDaemonProcess 192.168.10.11 processes=2 threads=15 display-name=%{GROUP} python-home=/home/five/NewsDesk/env/lib/python3.8
WSGIProcessGroup 192.168.10.11
<directory /home/five/NewsDesk/server>
<Files wsgi.py>
Allow from all
Require all granted
</Files>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/five/NewsDesk/server/staticfiles/
<Directory /home/five/NewsDesk/server/staticfiles>
Require all granted
</Directory>
</VirtualHost>
apache2ctl -S
答案 0 :(得分:1)
我想,您的django
项目应具有以下结构:
. home
.. five
.. NewsDesk
.. server # Your Django project root folder
.. server
.. settings.py
.. wsgi.py
..
.. staticfiles # Your public folder to collect assets (js, css, img ..)
# and served using apache
.. manage.py
要使用django
服务器本地服务/公开您的apache
项目,您需要在以下位置进行一些更改:
<VirtualHost *:80>
# ServerName localhost
ServerName myapp.local # rename your server
DocumentRoot /home/five/NewsDesk/server
WSGIScriptAlias / /home/five/NewsDesk/server/server/wsgi.py
# adjust the following line to match your Python path
# i intentionnally commented the 2 lines below
# WSGIDaemonProcess 192.168.10.11 processes=2 threads=15 display-name=%{GROUP} python-home=/home/five/NewsDesk/env/lib/python3.8
# WSGIProcessGroup 192.168.10.11
<directory /home/five/NewsDesk/server/server> # HERE a missing "/server"
<Files wsgi.py>
# Allow from all
Require all granted
</Files>
# AllowOverride all
# Require all granted
# Options FollowSymlinks
</directory>
Alias /static /home/five/NewsDesk/server/staticfiles # HERE remove the triailling "/"
<Directory /home/five/NewsDesk/server/staticfiles>
Require all granted
</Directory>
</VirtualHost>
(取决于linux
发行版以及apache
的安装和配置方式)
127.0.0.1 myapp.local
ALLOWED_HOSTS = [
'127.0.0.1', 'localhost',
'192.168.10.11', 'myapp.local',
]
现在,要在本地公开您的应用,请使用以下命令
python manage.py runserver YOUR_IP_ADDRESS:PORT
但对于您而言,应该是:
python manage.py runserver 192.168.10.11
让我知道这对您是否有用