如何让django呈现默认主页而不是apache
how to make django render the default home page instead of apache
众所周知,在通过web explorer 发出具有唯一IP 或服务器名称的请求后,apache 将return 其默认静态主页提供给explorer。我正在使用带有 mod_wsgi 的 django 和 apache 来部署我的站点(即 apache 网络服务器上的 django 应用程序)。当我向该服务器 运行 apache 发出请求时,如何将处理路由到 views.py 中定义的 django 映射规则以动态生成该站点的主页(即索引页)?提前致谢!
我在主 Apache 'httpd.conf' 中添加了以下配置:
<VirtualHost 127.0.0.1:80>
ServerName 127.0.0.1
ServerAlias example.com
ServerAdmin webmaster@example.com
DocumentRoot /usr/local/www/documents
Alias /robots.txt /usr/local/www/documents/robots.txt
Alias /favicon.ico /usr/local/www/documents/favicon.ico
Alias /media/ /usr/local/www/documents/media/
<Directory /usr/local/www/documents>
Require all granted
</Directory>
WSGIDaemonProcess 127.0.0.1 processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup 127.0.0.1
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
myapp.wsgi中的代码:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
然后我发出 127.0.0.1,资源管理器显示 'It works!',这是 apache 生成的默认页面,而不是我想要 'Hello world!' returned 在这种情况下。我只是希望在刚刚下发一个IP或站点地址时,生成默认主页的工作直接委托给django动态处理,而不是交给Apachereturn一个静态的index.html。虽然我配置了 WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
,这似乎还是不行。
虚拟主机不适用于 127.0.0.1,因为它被视为有点特殊。除非那是您的配置中唯一的 VirtualHost
,否则将要发生的是 Apache 将回退到使用它找到的第一个 VirtualHost
定义,通常是默认站点。
所以通常你会:
<VirtualHost *:80>
ServerName my.fqdn.host.name
...
</VirtualHost>
也就是说,VirtualHost
指令中没有 IP,ServerName
是出现在 URL 中的实际主机名,而不是 IP 地址。
在 httpd.conf
中是否有一个先前的 VirtualHost
,或者它是否包括 extra/httpd-vhosts.conf
,这将导致 VirtualHost
取代这个?
众所周知,在通过web explorer 发出具有唯一IP 或服务器名称的请求后,apache 将return 其默认静态主页提供给explorer。我正在使用带有 mod_wsgi 的 django 和 apache 来部署我的站点(即 apache 网络服务器上的 django 应用程序)。当我向该服务器 运行 apache 发出请求时,如何将处理路由到 views.py 中定义的 django 映射规则以动态生成该站点的主页(即索引页)?提前致谢!
我在主 Apache 'httpd.conf' 中添加了以下配置:
<VirtualHost 127.0.0.1:80>
ServerName 127.0.0.1
ServerAlias example.com
ServerAdmin webmaster@example.com
DocumentRoot /usr/local/www/documents
Alias /robots.txt /usr/local/www/documents/robots.txt
Alias /favicon.ico /usr/local/www/documents/favicon.ico
Alias /media/ /usr/local/www/documents/media/
<Directory /usr/local/www/documents>
Require all granted
</Directory>
WSGIDaemonProcess 127.0.0.1 processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup 127.0.0.1
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
myapp.wsgi中的代码:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
然后我发出 127.0.0.1,资源管理器显示 'It works!',这是 apache 生成的默认页面,而不是我想要 'Hello world!' returned 在这种情况下。我只是希望在刚刚下发一个IP或站点地址时,生成默认主页的工作直接委托给django动态处理,而不是交给Apachereturn一个静态的index.html。虽然我配置了 WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
,这似乎还是不行。
虚拟主机不适用于 127.0.0.1,因为它被视为有点特殊。除非那是您的配置中唯一的 VirtualHost
,否则将要发生的是 Apache 将回退到使用它找到的第一个 VirtualHost
定义,通常是默认站点。
所以通常你会:
<VirtualHost *:80>
ServerName my.fqdn.host.name
...
</VirtualHost>
也就是说,VirtualHost
指令中没有 IP,ServerName
是出现在 URL 中的实际主机名,而不是 IP 地址。
在 httpd.conf
中是否有一个先前的 VirtualHost
,或者它是否包括 extra/httpd-vhosts.conf
,这将导致 VirtualHost
取代这个?