django使用在子域中提供的静态和媒体文件设置nginx

时间:2011-11-24 14:31:19

标签: django nginx

当我尝试使用mocorner.com/static这样的东西时,我设法配置ngnix并运行它,但是当我尝试static.mocorner.com时它将我带到登陆页面。

以下是我的ngnix配置文件,有人可以建议我如何解决这个问题吗?另外我如何分离每个静态和媒体的日志?

upstream backend {
  server 127.0.0.1:8080;
}

server {
            listen   80;

            access_log /home/mocorner/moapps/mocorner/logs/static-nginx-access.log;
            error_log /home/mocorner/moapps/mocorner/logs/static-nginx-error.log;

            location / {
                        proxy_pass  http://backend;
                        include     /etc/nginx/proxy.conf;
        }
        location /static {
            root  /home/mocorner/moapps/mocorner/app/static;
    }
        location /media {
            root  /home/mocorner/moapps/mocorner/media;
    }
}

1 个答案:

答案 0 :(得分:2)

upstream backend {
  server 127.0.0.1:8080;
}

server {
    listen 80;
    server_name www.mydomain.com
    access_log /home/mocorner/moapps/mocorner/logs/static-nginx-access.log;
    error_log /home/mocorner/moapps/mocorner/logs/static-nginx-error.log;
    location / {
        proxy_pass http://backend;
        include    /etc/nginx/proxy.conf;
    }
}
server {
    listen 80;
    server_name media.mydomain.com
    access_log /home/mocorner/moapps/mocorner/logs/media-access.log;
    error_log /home/mocorner/moapps/mocorner/logs/media-error.log;
    root /home/mocorner/moapps/mocorner/media;
}
server {
    listen 80;
    server_name static.mydomain.com
    access_log /home/mocorner/moapps/mocorner/logs/static-access.log;
    error_log /home/mocorner/moapps/mocorner/logs/static-error.log;
    root /home/mocorner/moapps/mocorner/app/static;
}