我正在尝试使用nginx作为django的简单负载均衡器,每个Jacob Kaplan-Moss的例子: http://github.com/jacobian/django-deployment-workshop http://python.mirocommunity.org/video/1689/pycon-2010-django-deployment-w
如果我停止nginx并让apache在端口80上侦听一切正常。如果我听到nginx的apache我的网址会中断。
当nginx正在运行时,http://184.106。 。 / admin /有效,但http://184.106。 。 / admin(缺少结尾斜杠)中断。它会重定向到Web服务器http://web1/admin/
的名称我知道这是导致问题的nginx,因为重定向在apache和django dev服务器中工作正常。
以下是正在运行的nginx.conf:
# 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;
}
}
}
答案 0 :(得分:1)
我遇到了与Jacob的nginx示例完全相同的问题,并且没有斜线会导致不正确的重定向。 pjmorse的回复帮助了我,我在服务器块(server {server_name:vasir.net; ....)中设置了server_name,它修复了问题。但是,我必须先重启服务器