问题原文
原帖链接 · Jakxna360 · CC BY-SA 3.0
Hello and thank you for helping me. I recently added an ssl certificate to my site. It worked for a little bit but now I am getting a "too many redirects loop" in the browsers. I don't know much about servers (I'm following an online guide) so it might just be a rookie mistake.
Here is the file:
upstream app_server {
server unix:/var/run/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:80 default ipv6only=on;
root /home/example/public;
server_name www.example.com;
rewrite ^(.*) https://www.example.com$1 permanent;
ssl_certificate /example.com.chained.crt;
ssl_certificate_key /example.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
index index.htm index.html;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|$
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
已采纳解答
原帖链接 · Michael Hampton · CC BY-SA 3.0
It's a rookie mistake.
You have placed the redirect in your https server block:
rewrite ^(.*) https://www.example.com$1 permanent;
Which just redirects back to the same URL.
When you remove that, you should be fine. The redirect should only be in the block serving http on port 80, not in the block serving https on port 443.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
