添加ssl证书后,Nginx会导致无限重定向循环

时间:2015-11-02 18:56:57

标签: ssl nginx

我已将ssl证书添加到我的网站,并导致重定向循环。 之前工作得很好。 我试过了:

和我找到的其他解决方案, 我怀疑它可能与文件权限有关,但我没有找到任何东西。 我也尝试将我的crt和密钥文件放在/ etc / ssl中。

这是我的default.website文件:

server {
    listen      80;
    server_name www.example.com example.com;
    rewrite     ^   https://$server_name$request_uri? permanent;
    }


server {
    listen 443;

    ssl on;
    ssl_certificate /etc/nginx/ssl/ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/private.key;

    #listen       80 default_server;
    #listen       [::]:80 default_server;
    server_name  example;
    access_log /var/log/nginx/whcms.log;

    location / {
            root   /usr/share/nginx/html/example.com;
            index index.php index.html;
            try_files $uri $uri/ /index.php?$args;
    }

    location /ngx_status_2462 {
      stub_status on;
      access_log   off;
      allow all;
    }

    #location / {
    #        index index.php index.html;
    #        try_files $uri $uri/ /index.php?$args;
    #}


    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/example.com$fastcgi_script_name;
            fastcgi_param CCODE $geoip_country_code;
            include fastcgi_params;
    }

    error_page  404              /404.html;

    location = /404.html {
        root   /usr/share/nginx/html;
    }


    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

这是我的nginx.conf文件:

user  nginx;
worker_processes  12;
worker_rlimit_nofile 100000;
error_log   /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  100000;
    use epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    keepalive_requests 0;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$host" "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

   set_real_ip_from   0.0.0.0/0;
   real_ip_header     CF-Connecting-IP;

    geoip_country   /usr/share/GeoIP/GeoIP.dat;


    access_log  /var/log/nginx/nginx-access.log  main  buffer=256k;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    server_tokens   off;

## Caching files
...

## Size Limits
  ...

## Timeouts
  ...

## Compression
  ...

  #include /etc/nginx/sites-enabled/*;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;
    index  index.php index.html index.htm;
    include /etc/nginx/websites/*.website;


}

这是错误日志(添加调试后):

2015/11/03 09:22:09 [notice] 30330#0: *1 "^" matches "/", client: <ip_addr>, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
2015/11/03 09:22:09 [notice] 30330#0: *1 rewritten redirect: "https://example.com/", client: <ip_addr>, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
2015/11/03 09:22:10 [notice] 30330#0: *2 "^" matches "/", client: <ip_addr>, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
2015/11/03 09:22:10 [notice] 30330#0: *2 rewritten redirect: "https://example.com/", client: <ip_addr>, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
2015/11/03 09:22:10 [notice] 30330#0: *1 "^" matches "/", client: <ip_addr>, server: example.com, request: "GET / HTTP/1.1", host: "example.com"

服务器IP地址在哪里

我正在使用cloudflare作为我的DNS提供商

1 个答案:

答案 0 :(得分:0)

我看到的第一个是443服务器中的server_name错误。

回顾你的443听,你应该是:

listen 443 ssl;

您使用的是AWS ELB吗?