Deployment: Apache2, wsgi (Debian squeeze)

119 views
Skip to first unread message

Matt Smith

unread,
Jul 2, 2012, 11:03:08 PM7/2/12
to django...@googlegroups.com
Hi,

I made a multi choice quiz using django and was able to deploy it at:

http://mattsmith.org.nz/django/test

Thanks to the community for making these tools available.

I am a self-taught programmer, this is the first time I have tried any
web development so please be patient. I always find these groups
intimidating but I really feel I have made a decent RTFM effort before
making this post.

Here are some things I know nothing about:

Apache configuration.
How http actually works.

Up until now I've been serving non-dynamic content the usual way. I
apt-got installed apache2, worked out /var/www was the root, followed
the index.html convention and that worked fine. Now I feel I'm stuck
between that old way of doing things and the django/wsgi way which I
can't get my head around even after reading the docs. The development
server experience hasn't helped me much when it comes to deployment.

I wanted to connect the quiz to http://mattsmith.org.nz/test instead of
http://mattsmith.org.nz/django/test but I couldn't see how to do that.

I also want to convert the whole site to django so I can use child
templates, but I cant work this out either.

I guess my main question is this:

Under the old scheme if someone types just my domain into their browser
they get $DOCUMENT_ROOT/index.html, simple. What is the equivalent for
the django/wsgi setup.? What do you put in urls.py?

After reading the docs (they all say different things) I ended up with
the following setup:

/var/www/{oldStuff}
/var/django/dogscience/apache/django.wsgi

To help you help me you can see the following files from my system at
http://mattsmith.org.nz/pleasehelp

/etc/apache2/httpd.conf
/var/django/dogscience/settings.py
/var/django/dogscience/urls.py
/var/django/dogscience/apache/django.wsgi

Thank you,

--
Matt Smith
http://mattsmith.org.nz

kenneth gonsalves

unread,
Jul 3, 2012, 3:30:19 AM7/3/12
to django...@googlegroups.com
On Tue, 2012-07-03 at 15:03 +1200, Matt Smith wrote:
> Now I feel I'm stuck
> between that old way of doing things and the django/wsgi way which I
> can't get my head around even after reading the docs.

I would suggest that you start with trying to understand the concept of
virtual host in Apache. Try to set up a virtual host serving static
content at the start and once you understand that, things will start
falling in place (I am from a similar background from you, and thats how
I did it.
--
regards
Kenneth Gonsalves

Rohan

unread,
Jul 3, 2012, 4:55:03 AM7/3/12
to django...@googlegroups.com
If you change '/django' to '/' in your WSGIScriptAlias directive, then
everything will be forwarded to django, but apache will no longer check
in DocumentRoot since all url paths begin with a '/' and will be matched
by your wsgi alias

This means you would need another way of handling static content that
doesn't need to be rendered by django. I personally use an nginx proxy
in front of apache which serves static content directly and forwards
dynamic requests to apache.

In answer to your question of how you handle the same problem through
urls.py, you can use the django static files app as explained in
https://docs.djangoproject.com/en/dev/howto/static-files/

For example, having the following in urls.py

url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT,}),

lets django serve requests beginning with '/media' directly if your
media files are located at MEDIA_ROOT simlar to how apache serves
content from DocumentRoot. However, as the django documentation
explains, this is highly inefficient, and NOT recommended for production
since webservers do a better job of handling static content. As Kenneth
suggested, setting up a virtual host in apache is an excellent way to
start off.

Melvyn Sopacua

unread,
Jul 4, 2012, 9:45:06 AM7/4/12
to django...@googlegroups.com
On 3-7-2012 5:03, Matt Smith wrote:

> Up until now I've been serving non-dynamic content the usual way. I
> apt-got installed apache2, worked out /var/www was the root, followed
> the index.html convention and that worked fine. Now I feel I'm stuck
> between that old way of doing things and the django/wsgi way which I
> can't get my head around even after reading the docs. The development
> server experience hasn't helped me much when it comes to deployment.

In general Apache is easier to configure than nginx, but I find this not
to be the case with wsgi. If you're not set on Apache, then I suggest
you read the uwsgi deployment guide in the manual. I (and others on the
list) will gladly help you with the nginx bit, but I'd rather not
confuse you more if you're set on Apache, so I'm holding off on the
examples for now.

--
Melvyn Sopacua


Matt Smith

unread,
Jul 9, 2012, 3:25:16 AM7/9/12
to django...@googlegroups.com
Thx Kenneth, Rohan, Melvyn.

I've arrived at something that works:

httpd.conf:
WSGIScriptAlias /
/usr/local/django/projectName/apache/django.wsgi
Alias /static
/usr/local/django/projectName/static

So everything that's not a template lives under
/usr/local/django/projectName/static. Is this ok? Does this mean when I
link to say /static/foo.jpg in a template that foo.jpg is being served
up by apache directly, ie not handled by wsgi?

I've noticed that the site is slower to load up than before django? Is
this normal?

--
Matt Smith
http://www.mattsmith.org.nz
http://www.dogsciencenz.com


Rohan

unread,
Jul 9, 2012, 4:08:31 PM7/9/12
to django...@googlegroups.com
Hi Matt,
If you do not have static serving enabled in your django application
mapping to /static/ in urls.py, then the content is being served by Apache.

What is your MaxRequestsPerChild in your apache conf?

One of the reasons production environments use a different web server
for serving static content is that wsgi applications are blocking
applications and the server blocks activity until the wsgi request is
handled. This could affect your performance for concurrent requests if
you have a single process

Matt Smith

unread,
Jul 15, 2012, 2:22:05 AM7/15/12
to django...@googlegroups.com
On 10/07/12 08:08, Rohan wrote:
> Hi Matt,
> If you do not have static serving enabled in your django application
> mapping to /static/ in urls.py, then the content is being served by
> Apache.

In settings.py I commented out the lines which assign MEDIA_ROOT,
MEDIA_URL, and ADMIN_MEDIA_PREFIX because I couldn't see what they were
good for, and I have no entry for /static/ in urls.py so I guess the
content is being served by Apache, correct?
>
> What is your MaxRequestsPerChild in your apache conf?

0 for all of prefork, worker and event mpm's

I apologise if this is OT for this list but I'm curious if you think the
machine running apache is underpowered:

mds@waianakarua:~$ grep MHz /proc/cpuinfo
cpu MHz : 400.829
mds@waianakarua:~$ grep MemTotal /proc/meminfo
MemTotal: 185644 kB

Thx again,
Reply all
Reply to author
Forward
0 new messages