我有以下configuration:
Nginx>清漆> Gunicorn> Django
我想caching与同一个网站(移动和networking)的2个版本与清漆。
Gunicorn:
WEB: gunicorn_django --bind 127.0.0.1:8181 MOBILE: gunicorn_django --bind 127.0.0.1:8182
Nginx的:
WEB:
server { listen 80; server_name www.mysite.com; location / { proxy_pass http://127.0.0.1:8282; # pass to Varnish proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
移动:
server { listen 80; server_name m.mysite.com; location / { proxy_pass http://127.0.0.1:8282; # pass to Varnish proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
清漆:default.vcl
backend mobile_mysite { .host = "127.0.0.1"; .port = "8182"; } backend mysite { .host = "127.0.0.1"; .port = "8181"; } sub vcl_recv { if (req.http.host ~ "^m.mysite.com$") { set req.http.host = "m.mysite.com"; set req.backend = mobile_mysite; }elsif (req.http.host ~ "^(www.)?mysite.com$") { set req.http.host = "mysite.com"; set req.backend = mysite; } if (req.url ~ ".*/static") { /* do not cache static content */ return (pass); } }
VARNISH命令:
/usr/local/sbin/varnishd -P /var/run/varnish.pid -a 127.0.0.1:8282 -f /etc/varnish/default.vcl -T 127.0.0.1:6082 -t 120 -w 50,1000,120 -u varnish -g varnish
问题:
在Nginx上,如果我使用Varnish(端口8282)设置Mobile版本,并且使用Gunicorn(端口8181)让WEB版本,MOBILE通过清漆caching,则WEB&MOBILE都可以工作,但WEB不会被caching。 如果我将WEB版本的proxy_pass设置为Varnish(端口8282)并重新启动Nginx,则在访问networking版(www.mysite.com)时出现错误“redirect太多”。
我认为我的问题来自光油configuration文件,因为如果我设置Nginx的proxy_pass Gunicorn端口(移动和networking),该网站运作良好。