7

I am trying to give a Domain name and run multiple django projects on my apache, for the moment I managed to host one application and and run it on 127.0.0.1:8888 the settings look like this.

WSGIScriptAlias / C:/Users/ShabeerSheffa/workspace/ApacheDemo/ApacheDemo/wsgi.py
WSGIPythonPath C:/Users/ShabeerSheffa/workspace/ApacheDemo

<Directory C:/Users/ShabeerSheffa/workspace/ApacheDemo>
    <Files wsgi.py>
        Order deny,allow
        Allow from all
    </Files>
</Directory>

I tried changing the above code to look like the code below, with a domain name so i could access it using apachedemo.com but failed miserably.

NameVirtualHost apachedemo.com   

<VirtualHost apachedemo.com>    
    ServerName apachedemo.com  
    ServerAlias www.apachedemo.com

    WSGIScriptAlias / C:/Users/ShabeerSheffa/workspace/ApacheDemo/ApacheDemo/wsgi.py
    WSGIPythonPath C:/Users/ShabeerSheffa/workspace/ApacheDemo

    DocumentRoot C:/Users/ShabeerSheffa/workspace/ApacheDemo

    <Directory C:/Users/ShabeerSheffa/workspace/ApacheDemo>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>    

</VirtualHost> 

I am currently using port 8888 for my apache on a windows 7 machine, 127.0.0.1:8888 worked for the first version of the code, but after editing the code apache gives an error when restarting apache.

This is how my host file looks like, i only added the last line.(not quite sure why there is a # in second and third line)

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
    127.0.0.1:8888       apachedemo.com       www.apachedemo.com

I am trying to find answers for two questions-

  1. How do i make apachedemo.com work
  2. How do i add another project on the same server, example apachedemo2.com

EDIT: I am developing my projects using eclipse

Thanks alot for the help guys

shabeer90
  • 5,161
  • 4
  • 47
  • 65

3 Answers3

4

Try the below configuration out. You might also find this question useful and in the mod wsgi docs there is a section on virtualhosts that might help you as well.

WSGIPythonPath C:/Users/ShabeerSheffa/workspace/ApacheDemo

<VirtualHost apachedemo.com:8888>
    ServerName apachedemo.com
    WSGIScriptAlias / C:/Users/ShabeerSheffa/workspace/ApacheDemo/ApacheDemo/wsgi.py

    <Directory C:/Users/ShabeerSheffa/workspace/ApacheDemo>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>
</VirtualHost>

<VirtualHost apachedemo2.com:8888>
    ServerName apachedemo2.com
    WSGIScriptAlias / C:/Users/ShabeerSheffa/workspace/ApacheDemo/apachedemo2/wsgi.py

    <Directory C:/Users/ShabeerSheffa/workspace/ApacheDemo>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>
</VirtualHost>

Update

One of the comments below asked can you have different WSGIPythonPath in each virtualhost. Looking at the configuration docs WSGIPythonPath can only be in the context server config and not virtualhost. You can however add to the path in your wsgi files themselves as shown in this answer. You could also try and look at WSGIDaemonProcess with python-path as shown in this question.

Community
  • 1
  • 1
Marwan Alsabbagh
  • 25,364
  • 9
  • 55
  • 65
  • I am assumed I have to change to since my apache uses that port, it still did not work :| , "Oops! Google Chrome could not find apachedemo.com" – shabeer90 Nov 28 '12 at 15:54
  • yes you are right, it should be changed to 8888. I don't know why it's not working though. – Marwan Alsabbagh Nov 28 '12 at 15:58
  • i got your code to work :) , just want to know if i can have two different WSGIPythonPath's , because i have two projects running.. – shabeer90 Nov 29 '12 at 12:22
  • @shabeer90 check the updated answer for a solution to the WSGIPythonPath issue. – Marwan Alsabbagh Nov 29 '12 at 12:45
  • I tried WSGIPythonPath "C:/Users/ShabeerSheffa/workspace/ApacheDemo;C:/Users/ShabeerSheffa/workspace/ApacheDemo2" , but it only loads apachedemo.com and not apachedemo2.com, even tried out adding the path like you had shown on the answer you had given on another post, still does'nt work – shabeer90 Nov 29 '12 at 15:16
4

Make sure you read:

The auto generated wsgi.py file in Django 1.4 does things in a way that you cannot host two Django instances in same process under different sub interpreters. You will need to change the wsgi.py file.

This is in addition to any issues you may have with Apache configuration if you still have any. Since though you are being vague on exactly what the error is by giving any error messages, it is hard to guess what issue you are having is.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
0

The best solution is to run each Django project on it's own WSGI process within it's own Django instance.

WSGIPythonPath /var/www/path/web:/var/www/path/api

WSGIDaemonProcess api_wsgi user=user group=group
WSGIScriptAlias /api /var/www/path/api/wsgi.py
<Location /api>
WSGIProcessGroup api_wsgi
</Location>
 
WSGIDaemonProcess web_wsgi user=user group=group
WSGIScriptAlias /web /var/www/path/web/wsgi.py
<Location /web>
#SetEnv DJANGO_SETTINGS_MODULE project.settigs
WSGIProcessGroup web_wsgi
</Location>
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260