开发者

Django nginx and append slashes problem

I am trying to use nginx as a simple load balancer for django per Jacob Kapl开发者_如何学Can-Moss' example: http://github.com/jacobian/django-deployment-workshop http://python.mirocommunity.org/video/1689/pycon-2010-django-deployment-w

If I stop nginx and have apache listen on port 80 everything works fine. If I have apache listening to nginx my urls break.

When nginx is running, http://184.106../admin/ works, but http://184.106../admin (missing ending slash) breaks. It redirects to the name of the web server http://web1/admin/

I know it is nginx causing the issue because the redirect works fine in apache and django dev server.

Here is the nginx.conf that is running:

# Nginx conf (/etc/nginx/nginx.conf).

#
# Basic setup
#

user www-data;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

#
# Event/worker setup.
#

worker_processes 4;
events {
    worker_connections 100;
}

#
# HTTP configuration
#

http {
    include /etc/nginx/mime.types;

    # HTTP upstream for load balancers.
    # Replace the IPs below with IPs (or names) of your upstream Apaches
    upstream sitename {
        server 10.X.X.X:8000;
        server 10.X.X.X:8000;
    }

    # The actual HTTP sever.
    server {
        listen 80;

        # Don't proxy static files like robots.txt and favicon.ico.
        location ~ ^/(favicon.ico|robots.txt|sitemap.xml)$ {
            alias /home/web/static/$1;
        }

        # Serve media directly out of Nginx for performance
        location /media {
            alias /home/media;
        }

        # Proxy everything else to the backend
        location / {
            proxy_pass http://sitename;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;      
            add_header X-Handled-By $upstream_addr;      
        }
    }
}


I had the exact same problem you had, following Jacob's nginx example, and not having a slash would cause improper redirects. pjmorse's response helped me, I set the server_name in the server block ( server { server_name: vasir.net; .... ) and it fixed the problem. However, I had to restart the server first and

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜