Python Django With Apache Virtual Host

Do you like this?

Summary:
This post shows you the steps to set up virtual Host for Django projects. The environment used in this project was Mac OS.


Content:

1) Set Up Hosts File

vim /etc/hosts
127.0.0.1       your-site.com

2) Set Up Virtual Hosts For Apache

vim /etc/apache2/httpd.conf
NameVirtualHost *:80

<VirtualHost *:80>
	ServerName localhost
	ServerAlias 127.0.0.1
	DocumentRoot "/Library/WebServer/Documents"
	#or your own path to the default web server's documents
</VirtualHost>

<VirtualHost *:80>
	ServerAdmin admin@your-site.com
	ServerName www.your-site.com
	ServerAlias your-site.com
	
	<directory /path/to/your/django/project>
		Order allow,deny
		Allow from all
	</directory>
	
	Alias /resources "/path/to/your/django/project/resources"
	<Directory "/path/to/your/django/project/resources">
                Order allow,deny
                Allow from all
	</Directory>

	Alias /resources_admin "/Library/Python/2.7/site-packages/django/contrib/admin/static/admin"
	<Directory "/Library/Python/2.7/site-packages/django/contrib/admin/static/admin">
                Order allow,deny
                Allow from all
	</Directory>
	
	DocumentRoot "/path/to/your/django/project"
	LogLevel warn
	WSGIScriptAlias / /path/to/your/django/project/myproject.wsgi
	<Files myproject.wsgi>
		Order allow,deny
		Allow from all
	</Files>
	CustomLog /private/var/log/apache2/your-site.access.log combined
	ErrorLog /private/var/log/apache2/your-site.error.log
	
</VirtualHost>

Similar steps can be done to set up virtual hosts on Windows

 
comments powered by Disqus