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':
<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>
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]
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi
Virtual hosts don't work in that way for 127.0.0.1 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
...
</VirtualHost>
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?