在ELB进入redirect循环后面的实例中,禁用https的某个path

我使用elb终止ssl。 我想强制/产品/ performanceummaries /仅为HTTP。 这是我现在正在玩的configuration

user www-data; worker_processes 2; pid /var/run/nginx.pid; events { worker_connections 1024; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 1; gzip_buffers 32 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; # uWSGI serving Django. upstream django { # Distribute requests to servers based on client IP. This keeps load # balancing fair but consistent per-client. In this instance we're # only using one uWGSI worker anyway. ip_hash; server unix:/tmp/uwsgi.sock; } server { listen 80; server_name www.7geese.com *.amazonaws.com; charset utf-8; # Your project's static media. location /static/ { alias /home/ubuntu/.virtualenvs/7geese/sevengeese/static_files/; } location /product/performancesummaries/ { if ($http_x_forwarded_proto = "https") { rewrite ^ http://$host$uri permanent; } uwsgi_pass django; include uwsgi_params; } # Finally, send all non-media requests to the Django server. location / { if ($http_x_forwarded_proto != "https") { rewrite ^ https://$host$uri permanent; } uwsgi_pass django; include uwsgi_params; } } } 

当我访问/产品/ performanceummaries / ,它进入一个无限的redirect循环redirect从http到https到http等。为什么会去一个无限的redirect循环,我该如何阻止它。

您有两个location块,其中一个将/product/performancesummaries/ HTTPSredirect到HTTP /product/performancesummaries/

  if ($http_x_forwarded_proto = "https") { rewrite ^ http://$host$uri permanent; } 

另一个将HTTPredirect到/ (这是一切)的HTTPS:

  if ($http_x_forwarded_proto != "https") { rewrite ^ https://$host$uri permanent; } 

这可能是问题的原因,但我不完全确定为什么这两个location将被处理。 nginx似乎在less数情况下是这样做的 。

我会尝试解决这个通过排除 /product/performancesummaries/location / HTTP到HTTPSredirect:

  rewrite ^((?!/product/performancesummaries/).) https://$host$uri permanent; 

上述configuration没有任何问题。 无限循环导致redirect在我的Django应用程序redirecthttp请求到https。 哎呀!