2015-11-02 73 views
0

我已将ssl证书添加到我的网站,并导致重定向循环。 它之前工作得很好。 我想:添加ssl证书后,Nginx会导致无尽的重定向循环

和其他解决方案,我发现, 我怀疑这可能与文件的权限,但我没有发现任何东西。 我试着把我的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提供程序

回答

0

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

和审查你的443听,但你应该是:

listen 443 ssl;

您使用的是AWS ELB?

+0

不,我使用我自己的服务器,它运行centos 7.1, 我已经尝试了不同的server_names,包括example.com www.example.com – user216112

+0

更改您的听443到'listen 443 ssl;' – AGL