簡體   English   中英

如何使用mod_wsgi在單個域下托管多個django項目?

[英]how to use mod_wsgi for hosting multiple django projects under single domain?

我有多個django項目,我想在同一個域下托管它們,例如: example.com/one<br> example.com/two

我已經搜索了各種解決方案,並找到了以下給出的鏈接,這對我幫助很大。 是否可以在同一個域下托管多個django項目?

從上面的閱讀,我知道我需要mod_wsgi ,但我很困惑,在哪里安裝這個mod_wsgi - 我需要安裝在每個項目文件夾下(單獨為每個myenv)或它應該只安裝一次。 請幫我介紹如何以及在何處安裝此mod_wsgi以及如何在同一域名下托管多個項目。

我會告訴你我們在項目中的表現。 我們有一個具有不同路由的Django項目。 例如/players/tablet 我們將項目托管在兩個Docker容器中。 我們有NGINX作為我們的反向代理。 NGINX根據路由將請求重定向到適當的容器。 NGINX面向世界。 但是,我不確定它是否對你有用。

安裝mod_wsgi取決於您的主機操作系統。 檢查說明。 如果您使用的是CentOS或RedHat,我建議您查看IUS社區; 它們為Python 3.6和mod_wsgi提供了一個包含yum可安裝包的存儲庫。 您安裝的mod_wsgi版本必須根據您在虛擬環境中運行的相同版本的Python進行編譯。

然后,您需要正確配置您的VirtualHost 如果您在根目錄中擁有主機,那么它必須在您的定義中排在最后。 這是一個例子:

<VirtualHost *:443>
  TimeOut 300
  SSLEngine On

  ServerName mysite.example.com

  # Set to the lobal Application Group
  WSGIApplicationGroup %{GLOBAL}
  # Pass Authorizations through to the WSGI app for Django REST Framework Token Auth
  WSGIPassAuthorization On

  WSGIDaemonProcess subsite-develop-https python-home=/web/subsite-develop/venv request-timeout=300 user=apache group=apache
  WSGIProcessGroup subsite-develop-https
  WSGIScriptAlias /subsite /web/subsite-develop/config/wsgi.py process-group=subsite-develop-https
  <Directory /web/subsite-develop/config>
    Require all granted
  </Directory>
  Alias /subsite/static/ /web/subsite-develop/static/
  <Directory /web/subsite-develop/static>
    Header always set Access-Control-Allow-Origin "*"
    Require all granted
  </Directory>

  WSGIDaemonProcess django-mysite-develop-https python-home=/web/django-mysite-develop/venv request-timeout=300 user=apache group=apache
  WSGIProcessGroup django-mysite-develop-https
  WSGIScriptAlias / /web/django-mysite-develop/config/wsgi.py process-group=django-mysite-develop-https
  <Directory /web/django-mysite-develop/config>
    Require all granted
  </Directory>
  Alias /static/ /web/django-mysite-develop/static/
  <Directory /web/django-mysite-develop/static>
    Header always set Access-Control-Allow-Origin "*"
    Require all granted
  </Directory>
  Alias /media/ /var/media/mysite-www/
  <Directory /var/media/mysite-www>
    Require all granted
  </Directory>
</VirtualHost>

這個例子將承載在一個站點/subsite/和另一個在根, / 請注意,根網站是最后一個。 這也意味着您將無法在根項目中使用route /subsite/ ,因為Apache將通過WSGIScriptAlias定義將其轉移到它。

這也適用於有TLS的網站; 你可能需要將443切換到80 ,如果你沒有使用TLS,則刪除SSLEngine On WSGIPassAuthorization適用於Django REST Framework令牌,您也可以將其刪除,但我已將其WSGIPassAuthorization更完整的示例。 這適用於Apache 2.4+,當他們切換到Require all granted語法時。

IUS社區,如果在RedHat / CentOS上: https//ius.io/

暫無
暫無

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

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