亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我如何使用 apache 訪問 django?apache 在 django 上顯示默認頁面

我如何使用 apache 訪問 django?apache 在 django 上顯示默認頁面

慕尼黑8549860 2023-09-26 14:09:47
當我嘗試通過 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 -SVirtualHost 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_defaultsPidFile: "/var/run/apache2/apache2.pid"Define: DUMP_VHOSTSDefine: DUMP_RUN_CFGUser: name="www-data" id=33 not_usedGroup: name="www-data" id=33 not_used
查看完整描述

1 回答

?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

我想,你的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>

/etc/主機

(取決于linux發行版以及apache安裝和配置方式)


127.0.0.1  myapp.local

settings.py

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

讓我知道這對您是否有用


查看完整回答
反對 回復 2023-09-26
  • 1 回答
  • 0 關注
  • 133 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號