我如何使用 apache 访问 django?apache 在 django 上显示默认页面

当我尝试通过 apache 服务器访问我的 lan IP 地址上的 django 时,我得到了 apache2 的默认页面。我也在运行 djangopython manage.py runsever命令并尝试使用192.168.10.11. 但它仍然显示apache的默认页面。我如何使用 apache 访问 django?


<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


$apache2ctl -S


VirtualHost configuration:

*:80                   is a NameVirtualHost

         default server localhost (/etc/apache2/sites-enabled/000-default.conf:1)

         port 80 namevhost localhost (/etc/apache2/sites-enabled/000-default.conf:1)

         port 80 namevhost localhost (/etc/apache2/sites-enabled/newsdesk.conf:1)

ServerRoot: "/etc/apache2"

Main DocumentRoot: "/var/www/html"

Main ErrorLog: "/var/log/apache2/error.log"

Mutex default: dir="/var/run/apache2/" mechanism=default 

Mutex watchdog-callback: using_defaults

PidFile: "/var/run/apache2/apache2.pid"

Define: DUMP_VHOSTS

Define: DUMP_RUN_CFG

User: name="www-data" id=33 not_used

Group: name="www-data" id=33 not_used


慕尼黑8549860
浏览 102回答 1
1回答

万千封印

我想,你的django项目应该具有以下结构:. home&nbsp; .. five&nbsp; &nbsp; &nbsp;.. NewsDesk&nbsp; &nbsp; &nbsp; &nbsp; .. server #&nbsp; Your Django project root folder&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.. server&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .. settings.py&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .. wsgi.py&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;..&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.. staticfiles #&nbsp; Your public folder to collect assets (js, css, img ..)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; and served using apache&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.. manage.py要使用服务器在本地提供/公开您的django项目,您需要进行一些更改:apache虚拟主机配置<VirtualHost *:80>&nbsp; # ServerName localhost&nbsp; ServerName myapp.local&nbsp; #&nbsp; rename your server&nbsp; DocumentRoot /home/five/NewsDesk/server&nbsp; WSGIScriptAlias / /home/five/NewsDesk/server/server/wsgi.py&nbsp;&nbsp;&nbsp; # adjust the following line to match your Python path&nbsp;&nbsp; # i intentionnally commented the 2 lines below&nbsp; # WSGIDaemonProcess 192.168.10.11 processes=2 threads=15 display-name=%{GROUP} python-home=/home/five/NewsDesk/env/lib/python3.8&nbsp; # WSGIProcessGroup 192.168.10.11&nbsp;&nbsp;&nbsp; <directory /home/five/NewsDesk/server/server>&nbsp; # HERE a missing "/server"&nbsp; &nbsp; <Files wsgi.py>&nbsp; &nbsp; &nbsp; # Allow from all&nbsp; &nbsp; &nbsp; Require all granted&nbsp; &nbsp; </Files>&nbsp; &nbsp; # AllowOverride all&nbsp; &nbsp; # Require all granted&nbsp; &nbsp; # Options FollowSymlinks&nbsp; </directory>&nbsp;&nbsp;&nbsp; Alias /static /home/five/NewsDesk/server/staticfiles&nbsp; # HERE remove the triailling "/"&nbsp; <Directory /home/five/NewsDesk/server/staticfiles>&nbsp; &nbsp; Require all granted&nbsp; </Directory></VirtualHost>/etc/主机(取决于linux发行版以及apache安装和配置方式)127.0.0.1&nbsp; myapp.localsettings.pyALLOWED_HOSTS = [&nbsp; '127.0.0.1', 'localhost',&nbsp; '192.168.10.11', 'myapp.local',]现在,要在本地公开您的应用程序,请使用以下命令python manage.py runserver YOUR_IP_ADDRESS:PORT但就你而言,它应该是:python manage.py runserver 192.168.10.11让我知道这对您是否有用
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python