Lexinton Ave Lexinton Ave - 3 years ago 171
Apache Configuration Question

how to make django render the default home page instead of apache

As is known, after issuing a request with a sole IP or server name through web explorer, apache will return its default static home page to the explorer. I'm using django and apache with mod_wsgi to deploy my site(i.e. django app on apache web server). How to route the processing to django mapping rules defined in views.py to dynamically produce a home page(i.e. index page) for that site when I issue a request to that server running apache? Thanks in advance!

I added the following configuration in the main Apache 'httpd.conf':


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

WSGIDaemonProcess processes=2 threads=15 display-name=%{GROUP}

WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi

<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all


Code in 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]

Then I issued, the explorer displayed 'It works!', which is the default page produced by apache, instead of which I wanted 'Hello world!' returned in this case. I just want that when just issued an IP or site address, the work of generating the default home page is directly delegated to django to dynamically handle rather than to return a static index.html by Apache. Although I configured
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
, this seems still not work.

Answer Source

Virtual hosts don't work in that way for as it is treated a bit special. What is going to happen, unless that is the only VirtualHost in your configuration, is that Apache will fall back to using the first VirtualHost definition it found, usually the default site.

So normally you would have:

<VirtualHost *:80>
    ServerName my.fqdn.host.name

That is, no IP in VirtualHost directive and ServerName is the actual hostname that appears in the URL, not an IP address.

Was there a prior VirtualHost in httpd.conf or was it including including extra/httpd-vhosts.conf, that would result in a VirtualHost superseding this one?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download