Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My django application hosted on Apache, and now I want to serve its static media through nginx, I don't have any prior experience in nginx...plus currently the static media is serve through Apache.. expecting some helping hand.

Apache 2.2 mod_wsgi nignx-0.7.65 Django 1.1.1

Thanks..

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Can you tell me what you have done till now. You have to install nginx and set up apache as a reverse proxy. You need to change the port apache listens on to 8080, and nginx will listen to port 80.

The request for static media will be delivered from disk directly, and the other files will be redirected to port 8080 to apache.

If you can ask some more specific questions I can help you with them.

Update

Check out Nginx solution for Apache ProxyPassReverse for an example on reverse proxy. For a more detailed example you can just ask and I will post it.

Better: Using Nginx as a Reverse Proxy to Get the Most Out of Your VPS

Update

Part of my nginx.conf for a subdomain looks like this:

server {
  listen      80;
  server_name domain.nl www.domain.nl ;
  error_log /var/www/vhosts/domain.nl/statistics/logs/error_log.nginx warn;

  location / {
    proxy_pass  http://www.domain.nl:8080$request_uri;
    include  /etc/nginx/proxy.conf;
  }

  location ~* ^.+\.(jpg|jpeg|gif|png|css|bmp|js|ico|swf)$ {
    root  /var/www/vhosts/domain.nl/httpdocs;
    expires 7d;
  }
 }

This listen to port 80 for domain.nl and www.domain.nl. When a request is recieved for non-static files the request is passed to port 8080 http://www.domain.nl:8080$request_ur.

When a request for static files is found jpg etc. This is given directly from disk /var/www/vhosts/domain.nl/httpdocs, the location where my website is stored.

share|improve this answer
    
I have setup both Apache 2.2 and nginx, Apache running on 80 and nginx is running on 8888. I'm kind of missed the points, I think I did the other way around but now I can directly access static media like localhost:8888/sites/media which is nginx. Now I can link Django's MEDIA_URL to this location, but I don't know weather it's correct or not. Please fill the gaps.. –  MMRUSer Apr 12 '10 at 3:23
    
Well this is usually done the other way around. If you link inside of django to your media than the request is still handled by apache. And this is not what you want. You want to let Nginx handle all the requests. I recomend you change this, it is not a hard setup. How is your server structure? Do you want to run subdomains, or is it a single domain setup? –  Saif Bechan Apr 12 '10 at 8:11
    
Thanks, well it's a single domain setup.. and I want to know some basic information.. 1.Where do I put static media Apache's root or nginx root or somewhere else and how do I map the location of it to the server..2. Where do actually my Django app is resides nginx or Apache.3. I didn't get this one "The request for static media will be delivered from disk directly, and the other files will be redirected to port 8080 to apache." please give me more detailed explanation –  MMRUSer Apr 12 '10 at 9:01
    
Have you checked out the second link I sent you: Using Nginx as a Reverse Proxy to Get the Most Out of Your VPS. Basically what you do is just work with Apache when you start. Make everything so it works in Apache. That will become the backend. And then when everything works just how you want it in Apache, then you can configure Nginx in front of it. There are some minor steps to do so. –  Saif Bechan Apr 12 '10 at 10:17
    
Now I get the idea.., Nginx is just pass the requests that come to 8080 (which is the actual back-end, so Apache will works normal) and any-other request that come to 80 (where static media is resides).. One more thing can you please post the configurations on Apache side (how Apache going to listen incoming request from nginx) –  MMRUSer Apr 12 '10 at 12:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.