Re: Understanding the use of Apache and nginix with Django

49 views
Skip to first unread message

Phang Mulianto

unread,
Sep 8, 2012, 12:18:14 PM9/8/12
to django...@googlegroups.com
Hi,

The apache or whatever the webserver you choose, should only serving static files, not .py files .

the / request to your webserver will be redirect to django process, whether it is uwsgi, or wsgi , or whatever service you choose to deploy.

Django runs as application server actually.

user -- web server  ---- application server --- db server

hope helps

rgds,
Mulianto

On Sat, Sep 8, 2012 at 10:49 PM, Reginald Choudari <adnancho...@gmail.com> wrote:
Hello,

I've just started working on deploying a Django hosted website on my VPS. Last night I finished configuring mod_wsgi with apache2.2 and had got the 'It works!' page running from my Django project. I read here (https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/) the following: 
Django doesn't serve files itself; it leaves that job to whichever Web server you choose.
We recommend using a separate Web server -- i.e., one that's not also running Django -- for serving media. Here are some good choices:
I don't really understand this. This morning I configured my urls.py and views.py to direct the '/' site url to an index.html template I created on the fly (just for sanity check). Although it wasn't working at first, I restarted apache2.2 service and the web page shows fine now. I don't understand the idea of hosting two web servers and how Django is involved with this if at all. 

To me, it seems like apache routes clients to the wsgi, and the wsgi returns with whatever http response it conjures up? Can someone shed some light on this?

Thanks,
RC

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9KrPNlJvEbwJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Psamathos

unread,
Sep 8, 2012, 12:19:57 PM9/8/12
to django...@googlegroups.com
If you are using only Apache with mod_wsgi, you will also need to set up Aliases for your media directories (like css, images, or user-uploaded files). This is because mod_wsgi doesn't serve static files, it is only used to generate the dynamic pages of your site. It's perfectly possible to use Apache alone to do this without employing another web server. However, if you are implementing a site that you expect will receive high load you may want to set up a separate web server to act as a reverse proxy to your apache/mod_wsgi server while also serving static files. This will allow you to use nginx to serve static files independently of apache, for which nginx is technically more efficient although in my opinion the actual difference in negligible. I would personally stick with an apache-only configuration unless you need the flexibility afforded by two separate web server configurations.

If you're using Django 1.4 you should be using the built-in staticfiles app: https://docs.djangoproject.com/en/1.4/howto/static-files/

Javier Guerra Giraldez

unread,
Sep 8, 2012, 2:57:00 PM9/8/12
to django...@googlegroups.com
On Sat, Sep 8, 2012 at 9:49 AM, Reginald Choudari
<adnancho...@gmail.com> wrote:
> Django doesn't serve files itself; it leaves that job to whichever Web
> server you choose.
> We recommend using a separate Web server -- i.e., one that's not also
> running Django -- for serving media. Here are some good choices:

some time ago, the recommended Apache module was mod_python, which ran
Python code in the same process as the media serving capabilities of
Apache. that led to suboptimal use of RAM

the advice was, and still is, to use different processes for media and
app code, therefore a separate webserver was a good advise if you used
mod_python.

now, mod_python is deprecated, and mod_wsgi manages a separate process
for Django. uwsgi does a similar thing. so, it's quite easy to do a
very good architecture with just Apache and mod_wsgi, or just nginx
and uwsgi. (there are still many other options, of course)

--
Javier
Reply all
Reply to author
Forward
0 new messages