I have set it up such that nginx proxies request and sends django requests to apache and serves media itself.
Following documents my setup:
Nginx Configuration: /etc/nginx/nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
include /etc/nginx/sites-enabled/*;
}
=====
ngnix proxy /etc/nginx/proxy.conf
============
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
===========
Nginx server file: /etc/nginx/sites-enabled/some-name.txt
==========
server {
listen 208.109.252.110:80;
server_name netconf;
autoindex on;
access_log /home/site/server_logs/nginx_access.log;
error_log /home/site/server_logs/nginx_error.log;
location / {
proxy_pass http://127.0.0.1:80/;
include /etc/nginx/proxy.conf;
}
location /site_media/ {
root /home/site/folder/static;
}
}
==========
Nginx very well proxies the request and passes to apache, the required requests, but doesn't serve the media. In the last server file, location site_media is not served, at all. 🙁
Everything seems perfect to me. What is wrong?
Thanks in advance.
Best Answer
Add something like this:
You will then have the files with those extension delivered from a different place. You can give then different expire dates and compression etc also.
The complete file would look like this:
You might also want to add some more options to your files. Check out the following links for some special options for dynamic and static content and some overall security issues.