您好请查看下面我的nginx配置。当我尝试访问我的主页http://mydomain.com时,我收到以下错误消息。当我使用Chrome开发者工具查看重定向时,我发现http://mydomain.com正在重定向到https://mydomain.com来回。我查看了我的源代码,但我找不到任何重定向。我正在使用ssl_requirement插件。
非常感谢任何帮助。
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
以下是我的nginx配置文件
server {
listen 80;
server_name www.mydomain.com;
rewrite ^/(.*) http://mydomain.com/$1 permanent;
}
server {
listen 80;
server_name mydomain.com;
access_log /var/www/mydomain/current/log/access.log;
root /var/www/mydomain/current/public;
passenger_enabled on;
passenger_use_global_queue on;
location ~ /\.ht {
deny all;
}
}
server {
listen 443;
ssl on;
ssl_certificate /home/ubuntu/ssl-cert/nopassphrase.pem;
ssl_certificate_key /home/ubuntu/ssl-cert/nopassphrase.key;
server_name www.mydomain.com;
rewrite ^/(.*) http://mydomain.com/$1 permanent;
}
server {
listen 443;
ssl on;
ssl_certificate /home/ubuntu/ssl-cert/nopassphrase.pem;
ssl_certificate_key /home/ubuntu/ssl-cert/nopassphrase.key;
server_name mydomain.com;
access_log /var/www/mydomain/current/log/access.log;
root /var/www/mydomain/current/public;
location ~* \.(ico|jpg|gif|png|css|js|swf|html)$ {
if (-f $request_filename) {
expires max;
break;
}
}
passenger_enabled on;
passenger_use_global_queue on;
location ~ /\.ht {
deny all;
}
}
答案 0 :(得分:1)
您的配置正在重定向到自身。
您可以将http和https放在同一个服务器块中。证书应该是链式证书,因为它不是自签名证书。
server {
listen 80;
server_name www.mydomain.com;
rewrite ^/(.*) http://mydomain.com/$1 permanent;
}
server {
listen 80;
listen 443 ssl;
server_name mydomain.com;
ssl_certificate /home/ubuntu/ssl-cert/nopassphrase.pem;
ssl_certificate_key /home/ubuntu/ssl-cert/nopassphrase.key;
location ~* \.(ico|jpg|gif|png|css|js|swf|html)$ {
if (-f $request_filename) {
expires max;
break;
}
}
access_log /var/www/mydomain/current/log/access.log;
root /var/www/mydomain/current/public;
passenger_enabled on;
passenger_use_global_queue on;
location ~ /\.ht {
deny all;
}
}