SHIVA
SHIVA

Reputation: 107

How to Run two django projects in one server

I am using python 2.7,django 1.4,and Apache2.2.21, I am able to run one project on Apache server, I want to use the same Apache and same server to run my second project.

I am using the following wsgi.py for my first project

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "product.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

and in Apache httpd.conf file using below code

LoadModule wsgi_module modules/mod_wsgi.so

At last of the file

WSGIScriptAlias / C:/Python27/Lib/site-packages/django/bin/product/product/wsgi.py

WSGIPythonPath /C:/Python27/Lib/site-packages/django/bin/product

<Directory C:/Python27/Lib/site-packages/django/bin/product/media>

Order allow,deny

Allow from all

</Directory>

<Directory C:/Python27/Lib/site-packages/django/bin/product>

Order allow,deny

 Allow from all

 </Directory>

<Directory  "C:/Python27/Lib/site-packages/django/contrib/admin/media">

Order deny,allow

Allow from all

</Directory>

Alias /static/admin/  C:/Python27/Lib/site-packages/django/contrib/admin/media/ 

Please help me out how can run the second project with wsgi.py path as C:/Python27/Lib/site-packages/django/bin/second/product/product/wsgi.py on same Apache server.

Upvotes: 2

Views: 2413

Answers (1)

JunYoung Gwak
JunYoung Gwak

Reputation: 2987

You should not write your application configuration(the code you added) on module configuration(mod_wsgi.so)

You should create application configuration file (usually at /var/www/apache2/sites-available/) and then enable it. In order to create multiple application, you should use VirtualHost.

For example,

/var/www/apache2/sites-available/application1.conf

<VirtualHost *:80>
ServerName www.application1.com

# Your application 1 configuration

</VirtualHost>

/var/www/apache2/sites-available/application2.conf

<VirtualHost *:80>
ServerName www.application2.com

# Your application 2 configuration

</VirtualHost>

Then, you should enable the application. Usually, the command is sudo apache2ensite application1 && sudo apache2ensite application2. The commnad might differ according to the distribution.

Finally, you should reload the apache sudo service apache2 reload.

I strongly suggest you to search for distribution-specific virtual host setup guide.

Upvotes: 3

Related Questions