too many redirects

Steve Holdoway steve at greengecko.co.nz
Thu Nov 20 22:30:16 UTC 2014


Here's a basic example of one of my configs that redirect example.wp.com
to https://www.example.wp.com...  update <myip> and example.wp.com as
necessary, and ensure the site is set up as www.example.wp.com as well.

It may need the odd tweak to restore to standard use of fastcgi
includes, as I've modified mine. Also care on folded lines.

server {
	listen <myip>:80;
    	server_name  example.wp.com www.example.wp.com;

    	return 301 https://www.example.wp.com$request_uri;
}

server {
	listen <myip>:443 ssl;
    	server_name  example.wp.com;

        ssl_certificate         /etc/nginx/ssl/www.example.wp.com.crt;
        ssl_certificate_key     /etc/nginx/ssl/www.example.wp.com.key;

    	return 301 https://www.example.wp.com$request_uri;
}

server {
	listen <myip>:443 ssl;

        server_name www.example.wp.com;
        server_name_in_redirect off;

        ssl_certificate         /etc/nginx/ssl/www.example.wp.com.crt;
        ssl_certificate_key     /etc/nginx/ssl/www.example.wp.com.key;

        access_log /var/log/nginx/www.example.wp.com.access.log main;
        error_log /var/log/nginx/www.example.wp.com.error.log notice;

        root /www/www.example.wp.com/public_html;

        # OCSP Stapling
        ssl_stapling on;
        ssl_stapling_verify on;
        resolver 127.0.0.1 8.8.8.8 8.8.4.4 valid=300s;
        resolver_timeout 5s;

#       Firefox cross site font face
        add_header Access-Control-Allow-Origin *;

        autoindex off;

        #index index.php index.html index.htm default.html default.htm;
        index index.php;

        # Support Clean (aka Search Engine Friendly) URLs
        location / {
                try_files $uri $uri/ /index.php?q=$request_uri;
        }

        # deny running scripts inside writable directories
        location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|
asp|sh|cgi)$ {
                return 403;
                error_page 403 /403_error.html;
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root
$fastcgi_script_name;
                fastcgi_pass backend;

        }

        # caching of files 
        location ~* \.(ico|woff|pdf|flv|js|css|png|jpg|jpeg|gif|swf|xml|
txt)$ {
                access_log off;
                expires 30d;
        }

}


On Thu, 2014-11-20 at 22:07 +0100, JACK LINKERS wrote:
> I completely lost...
> I tried everything (of my understanding) with no success.
> I didn't know you could include a condition with if and came across
> sites like :
> http://publications.jbfavre.org/web/nginx-vhosts-automatiques-avec-SSL-et-authentification.fr
> 
> This is way beyond my skills... I didn't managhe to enclose the 301 in
> if statements
> I think i'm gonna givin up
> 
> 2014-11-20 10:27 GMT+01:00 JACK LINKERS <jacklinkers at gmail.com>:
>         Hi guys,
>         
>         Thanks for your fast reply and input.
>         I didn't think of wordpress at all.
>         
>         I'll try some tuning and keep you posted.
>         
>         Thanks again
>         
>         Le 20 nov. 2014 09:52, "B.R." <reallfqq-nginx at yahoo.fr> a
>         écrit :
>                         On Thursday, November 20, 2014, JACK LINKERS
>                         <jacklinkers at gmail.com> wrote:
>                                 rewrite     ^   https://$server_name
>                                 $request_uri? permanent;
>                                 
>                 
>                 ​This looks highly suscpicious to me: unconditional
>                 rewrite of any request?
>                 
>                 
>                 Try to either:
>                 - match the regex against HTTP requests
>                 - enclose a 'return 301 [...]' in an 'if' directive
>                 checking for the HTTP scheme
>                 
>                 I am not 100% certain what would be the best
>                 alternative to go for.
>                 
>                 
>                 If the problem comes from there, I do not really get
>                 how the backend gets to serve any (error) page... So
>                 maybe Wordpress trouble as stated before.
>                 
>                 ---
>                 B. R.
>>                 
>                 
>                 
>                 
>                 _______________________________________________
>                 nginx mailing list
>                 nginx at nginx.org
>                 http://mailman.nginx.org/mailman/listinfo/nginx
> 
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

-- 
Steve Holdoway BSc(Hons) MIITP
http://www.greengecko.co.nz
Linkedin: http://www.linkedin.com/in/steveholdoway
Skype: sholdowa



More information about the nginx mailing list