Nginx configuration leads to endless redirect loop这是一个非常类似的问题,但这个讨论还没有让我得到答案。我正在学习如何使用nginx和ssl,一切都在常规的http:// example.com方面完美运行,但是当路由到https:// example.com/admin时,我会看到:< / p>
此网页有重定向循环
这是我的配置文件:
map $uri $example_org_preferred_proto {
default "http";
~^/(images|css|javascript)/ "none";
~^/admin/ "https";
}
server {
listen 80;
root /usr/share/nginx/www/example.com/blog;
server_name example.com;
if ($example_org_preferred_proto = "https")
return 301 https://example.com$request_uri;
}
location ~ / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:2368;
}
}
server {
listen 443;
ssl on;
root /usr/share/nginx/www/example.com/blog;
server_name example.com;
ssl_certificate /usr/share/nginx/<redacted>.crt;
ssl_certificate_key /usr/share/nginx/<redacted>.key;
if ($example_org_preferred_proto = "http") {
return 301 http://example.com$request_uri;
}
location ~ / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:2368;
}
}
基本上我想要完成的是拥有一个通常运行未加密的网站,但是当我指向我的管理页面时,浏览器会重定向到https并加密我的登录信息。
注意:映射的想法来自http://www.redant.com.au/ruby-on-rails-devops/manage-ssl-redirection-in-nginx-using-maps-and-save-the-universe/,似乎比使用重写更好的方法