Nginx – Serve static media on “nginx”

apache-2.2djangonginx

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..

Best Answer

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.