0

您好,请在下面查看我的 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;
    }
}
4

1 回答 1

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;
    }
}
于 2012-10-12T02:57:48.787 回答