Redirected too many times / redirecting in a way that will never complete

Hi,

starting a new topic because we’re deviating from the original.

Trying to get EE to work on top of an existing nginx install (after cleaning removing as much as possible) and having many problems.

  • When accessing www.warner.photo the browser is giving “redirected too many times” (chrome) or “redirected in a way that will never complete” (mozzilla) error.

  • When accessing www.warner.photo/wp-login.php directly the browser shows the login screen correctly

  • After putting credentials (or clicking 'back to warner.photo) on the login screen, I’m redirected to the local IP (192.168.x.x), which obviously is not available from the outside

Can anyone point me in the right direction?

Thanks for any help! After two days I’m getting a bit desperate!

Warner

  • Site was set up with --w3tc

  • ee info --php comes back the user ‘empty’ (i.e. user is not www-data) (not sure if this is relevant)

  • error log shows “2017/06/13 10:41:32 [error] 8678#0: *50 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.254, server: warner.photo, request: “GET / HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “www.warner.photo”” (not sure if this is relevant)

Some further notes:

  • I’m running a “real” machine with some other functions as well (including others sql databases), so I can’t just start a new VM

  • After trying to clean the machine (ee purge and deleting /etc/nginx and so forth) I had to put things back manually because both nginx and ee were assuming to find the various .conf files

  • EE is not reinstalling / enabling the 22222 tools - which is something I’m trying to fix by manually putting files back as well.

  • I guess the challenge is to trick EE into thinking it has to install everything from scratch… but I haven’t managed!

Hi @warner

I saw the thread posted by you and understand that you are having many issues with nginx configurations. Don’t worry, we can try some basic checks to find out where is the exact issue.

Findings: (Redirection Issue) antopjoseph@apj-mbp  ~  curl -X GET -I www.warner.photo HTTP/1.1 301 Moved Permanently Server: nginx Date: Tue, 13 Jun 2017 11:58:26 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Location: http://warner.photo/

www.warner.photo is redirected to warner.photo causing 1st redirect. (see Location: )

and when I check warner.photo

antopjoseph@apj-mbp  ~  curl -X GET -I warner.photo HTTP/1.1 302 Found Server: nginx Date: Tue, 13 Jun 2017 11:58:32 GMT Content-Type: text/html; charset=utf-8 Content-Length: 48 Connection: keep-alive Location: http://www.warner.photo/ X-Served-By: Namecheap URL Forward

warner.photo is redirecting again back to www.warner.photo. Causing a redirect Loop.

For easy debugging replace all occurrances of www.warner.photo from nginx configuration and use warner.photo.

and make sure SITE_URL and HOME_URL in wp-config.php are same.

or use following inside your wp-config.php

define( 'WP_SITEURL', 'http://warner.photo' ); define( 'WP_HOME', 'http://warner.photo' );

@warner and regarding the error appeared in the log, most probably this would be similar to the issue specified here.

Also, since you have not installed EE on a clean machine, there might be old php-fpm running on the same port 9000. if there, you will need to uninstall all services which are not installed by EE.

(EasyEngine installation on a fresh machine is always preferred in order to avoid any conflicts between the packages/services.)

@antopjoseph thanks for the hints! now I removed www.warner.photo from the host file and (predictably) when I to to either www.warner.photo or warner.photo nginx redirects me to the default site… So that’s not enough.

The reverse also doesn’t work (the loop is there also if I just have www.warner.photo in the hosts file).

Any ideas what to try next?

Warner

@anto Ok. Updated /etc/php/7.0/fpm/pool.d/www.conf as follows:

  • Replaced “listen = /run/php/php7.0-fpm.sock” with “listen = 127.0.0.1:9070”

  • Restart service by systemctl restart php7.0-fpm.service

  • Running netstat -ntualp |grep :9070 now shows: “tcp 0 0 127.0.0.1:9070 0.0.0.0:* LISTEN 32226/php-fpm.conf)”

That fixed that part (just writing it down here so that it may help others).

Only the redirect left to fix :wink:

1 Like

Ok… on the redirect issue: perhaps I need to change my DNS records?

Now I have two records:

  • An “A Record” on “Host=www” pointing to my IP

  • An “URL Redirect Record” on “Host=@” pointing to “http://www.warner.photo”, unmasked.

Warner

Nice. It’s good to report your findings so that it will surely help someone in future.

Once I domain name is resolved to IP, DNS don’t have any role in redirection. and when I checked, your domain is showing nginx default page. Not redirection issue. (clear cache and check). So now make sure the document root specified is correct in configuration file (root /var/www/domain-root/htdocs) and also check the server_name is like server_name warner.photo www.warner.photo;

I removed the www.warner.photo from the .conf file so it started referring to default. Now I put it back - but also the problem is back.

On second thought… I have another site running Piwigo on the same server, using the same nginx config, the same setup in the hosts file (i.e. both www.example.site andexample.sitee in sites-available/example.site.conf file) and the same dns records setup… and that site is running just fine! This makes me thing the issue is with the wp site specifically for some reason.

… I’m totally lost… :sweat:

also adding the following inside the wp-config.php file (as per your suggestion) does not make a difference…

define( ‘WP_SITEURL’, ‘http://warner.photo’ ); define( ‘WP_HOME’, ‘http://warner.photo’ );

However… what DID work, is changing your suggestion to:

define( ‘WP_SITEURL’, ‘http://www.warner.photo’ ); define( ‘WP_HOME’, ‘http://www.warner.photo’ );

That worked! It would be great to understand why though… for the benefit of the learning curve ;).

I’m so happy right now! After two days of work…

@warner

Once nginx passes the request, the further processing is managed at wordpress end. Wrong SITEURL & HOMEURL which was not matching with the specified one in nginx resulted in a loop.

when we specify WP_SITEURL and HOME_URL in wp-config.php, we are overriding similar setting in your database (wp_options table). You can change the same using PhpMyadmin. :slight_smile:

And that’s it! You can help others with the same problem in the future!

1 Like

@anto thanks so much for your help. Surely I will do my best to support others now that I know a little more about how this works.

Anyhow, it’s still a little strange: how come the default setting (warner.photo in my case, so without www) is not matching the one specified in nginx? In the sites-enabled/warner.photo.conf both are specified. Is the core reason that the DNS sends www.warner.photo and not warner.photo? That would mean that the default EE setup is not compatible with the default setup of namecheap.com

@warner DNS have no role in this.

VPS provided by namecheap had some services which where running on the ports which are required for the services installed by EE.(nginx/phpfpm) caused first error.

Redirection and issue related to www. can be of many reasons like mismatching. If all configurations generated by EE (in fresh VPS) this won’t happen.