[英]Django Apache DocumentRoot?
必須將 Apache 中的 DocumentRoot 設置為運行 Django 應用程序的目錄是靜態目錄,但它不起作用? 感謝大家提前提供幫助。
您指向項目根目錄; wsgi.py
文件在哪里。 從文檔:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonHome /path/to/venv
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
靜態文件單獨配置。 詳情在這里。 示例(再次,來自文檔):
Alias /robots.txt /path/to/mysite.com/static/robots.txt
Alias /favicon.ico /path/to/mysite.com/static/favicon.ico
Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/
<Directory /path/to/mysite.com/static>
Require all granted
</Directory>
<Directory /path/to/mysite.com/media>
Require all granted
</Directory>
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
使用 Django 時,不需要DocumentRoot
指令。
在傳統的網站方法中,Apache 提供預先編寫的 HTML 文件,Apache 使用DocumentRoot
,比如說
DocumentRoot = /var/www/website
這樣當用戶請求像users/profile.html
這樣的資源時,它可以將其映射到文件系統文件/var/www/website/users/profile.html
,這是一個實際文件。
相比之下,在 Django 中,沒有可供 Apache 查找的預先編寫的 HTML 文件。 相反,所有請求都直接定向到 Django,后者動態構建 HTML 文件並返回該文件。 因此,Apache 不需要DocumentRoot
,它需要知道 Django 的 WSGI 應用程序文件wsgi.py
的位置,這是向 Django 發送 HTTP 請求的“網關”,以便它可以構造正確的 HTML 文件以返回。 這是由WSGIScriptAlias
指令和相關的 Apache 配置指定的; 例如
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
正如 Django 文檔中關於使用 Apache 部署 Django所給出的那樣。
TL;DR:你不需要DocumentRoot
,你需要WSGIScriptAlias
用於 Django。
我想你在問這個:
ServerAdmin example@localhost
DocumentRoot /var/www/html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.