Tuesday, March 14, 2017

To many redirects with https and nginx

I'm using cloudflare for a free SSL certificate. Now I would like to redirect my website to https. My nginx config looks like this:

server {
    listen       80;
    server_name  nielsvroman.be www.nielsvroman.be;

    # Force rewrite for everything that reaches this vhost to www.nielsvroman.be
    return 301 https://www.nielsvroman.be$uri;
}

server {
    listen 443 ssl;

    server_name www.nielsvroman.be;

    root /var/www/nielsvroman.be/html/public;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
            expires 14d;
        }

    location ~*  \.(pdf)$ {
            expires 30d;
        }

    location ~ /\.ht {
            deny all;
        }
}

But when I go to https://www.nielsvroman.be I'm getting the error ERR_TOO_MANY_REDIRECTS. What is wrong in my config?



via nielsv

Advertisement