WebFaction
Community site: login faq
1
2

Hi,

I have a django project up and running on Webfaction, but would now like to have it support multiple virtual hosts. All instances will use the same django project, just a different settings file and separate DB. I've been reading about setting up VirtualHosts in Apache, but I'm a little lost because the default httpd.conf doesn't already have a virtual host entry so I'm not sure what should go in that section versus what remains outside of it. Also, it seems there are different ways to set it up to be more efficient. Is there any documentation on how to go from a default httpd.conf to one with Virtual Host Entries?

Thanks

asked 29 Feb '12, 16:51

roam3greg
11113
accept rate: 0%


The VirtualHost entries should look like this:

NameVirtualHost *:YOUR_PORT

# Virtual Hosts

<VirtualHost *:YOUR_PORT>
    ServerName www.YOUR_DOMAIN.com
    ServerAlias YOUR_DOMAIN.com
    KeepAlive Off
    # The first "YOUR_DOMAIN.com" is just a process group.  The name is arbitrary.
    # The "display-name" shows up when running "ps -u YOUR_USERNAME -o pid,rss,command" to list processes.  Otherwise you can't tell which process belongs to which django app.
    WSGIDaemonProcess YOUR_DOMAIN.com processes=1 threads=20 inactivity-timeout=60 display-name=[wsgi-YOUR_APP_NAME]httpd
    WSGIProcessGroup YOUR_DOMAIN.com
    WSGIScriptAlias / /home/YOUR_USERNAME/webapps/django/wsgi/YOUR_APP_NAME.wsgi
</VirtualHost>
permanent link

answered 29 Feb '12, 18:06

seanf
12.2k41836
accept rate: 37%

edited 13 Mar '14, 00:42

OK, that was one of the references I was using, but wasn't sure how to implement it. My httpd.conf (in part) went from this:

WSGIDaemonProcess django processes=2 threads=12 python-path=/home/roam3/webapps/django:/home/roam3/webapps/django/lib/python2.7
WSGIProcessGroup django
WSGIScriptAlias / /home/roam3/webapps/django/django.wsgi
WSGIRestrictEmbedded On
WSGILazyInitialization On

To this:

#WSGIDaemonProcess django processes=2 threads=12 python-path=/home/roam3/webapps/django:/home/roam3/webapps/django/lib/python2.7
#WSGIProcessGroup django
#WSGIScriptAlias / /home/roam3/webapps/django/django.wsgi
WSGIRestrictEmbedded On
WSGILazyInitialization On

NameVirtualHost roam3.webfactional.com:23113

# Virtual Hosts

<VirtualHost roam3.webfactional.com:23113>
ServerAdmin greg@reservation-net.com
ServerName roam3.webfactional.com
KeepAlive Off
# The first "YOUR_DOMAIN.com" is just a process group.  The name is arbitrary.
# The "display-name" shows up when running "ps -u YOUR_USERNAME -o pid,rss,command" to list processes.  Otherwise you can't tell which process belongs to which django app.
WSGIDaemonProcess django1 processes=2 threads=12 python-path=/home/roam3/webapps/django:/home/roam3/webapps/django/lib/python2.7 inactivity-timeout=60 display-name=[wsgi-roam3_roam3]httpd
WSGIProcessGroup django
WSGIScriptAlias / /home/roam3/webapps/django/django.wsgi
</VirtualHost>

But I get a 404 error now. I've mucked about, but I don't know enough to know what's wrong.

(29 Feb '12, 19:10) roam3greg

I just fixed the formatting on your comment (you need to indent code blocks).

The NameVirtualHost and VirtualHost bits needs to include asterisks as I showed in my example, "*: 23113" and not "username.webfactional.com:23113".

Can you fix that, restart your Apache, and try again?

Also, this is a public forum, so you might want to leave sensitive details like your username and hostname out of your comments :)

(29 Feb '12, 19:17) seanf

Replacing the url with * generates a 500 Internal Server Error message. I had tried that originally. I also figured that couldn't be the answer as how would I setup multiple domains? A * on NameVirtualHost and url in VirtualHost block gives me a warning when restarting Apache, and a 404. So I think the error is in the VirtualHost block.

(29 Feb '12, 20:38) roam3greg

The Django Book shows working examples.

permanent link

answered 29 Feb '12, 21:56

johns
5.3k312
accept rate: 23%

The answer is that the setup I had was mostly correct. It does need *:port everywhere, but the problem was that the first value in WSGIDaemonProcess and the WSGIProcessGroup have to have the same value. However, if there are multiple <virtualhost> blocks the same Process name can't be used in each block.

permanent link

answered 01 Mar '12, 12:49

roam3greg
11113
accept rate: 0%

That's the reason that the example I provided used "YOUR_DOMAIN.com" in the WSGIProcessGroup and WSGIDaemonProcess directives - to ensure that it would match within each virtual host, and that it would be unique to each virtual host.

(01 Mar '12, 13:00) seanf
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×225
×28
×8

question asked: 29 Feb '12, 16:51

question was seen: 14,244 times

last updated: 13 Mar '14, 00:42

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM