WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 3 years ago

#9110 closed defect (bug) (wontfix)

Wordpress 2.7.1 behind Apache Proxy fails with incorrect hostname in URLs

Reported by: GavinCameron Owned by: markjaquith
Milestone: Priority: normal
Severity: normal Version:
Component: Canonical Keywords: needs-patch
Focuses: Cc:

Description

Recently upgraded from 2.7 to 2.7.1 using the automated upgrade option in wp-admin.

Environment is that we have an Apache server infront of the wordpress server. The Apache server (called www) acts as a proxy and does

ProxyPass / http://wordpressserver:11003/
ProxyPassReverse / http://wordpressserver:11003/

When running 2.7 requests were proxied correctly and all URLs generated by wordpress use 'www' as the host.

After upgrading to 2.7.1, the first request to 'www' hits the wordpress server, but the URLs generated by wordpress uses 'wordpressserver' as the host part of the URL rather than 'www'.
'wordpressserver' is not accessible from the internet, hence must be proxied. This setup has been working flawlessly for quite a while.

Admin access has not been affected, only end user access is broken.

No other changes have been made and all plugins have been disabled.

Blog is currently unreadable due to this problem.

Change History (12)

comment:1 GavinCameron5 years ago

More info, commenting out this line

add_action('template_redirect', 'redirect_canonical');

at the bottom of canonical.php makes blog work again.

Now, I think I've had to comment this line out in older versions of wordpress...

Still pointing to an issue with using wordpress in a proxied environment

comment:2 follow-up: DD325 years ago

Canonical is based upon your "Home" and "Site URL" options you set.

You need to set them to the publically-accessable name, NOT the private url.

comment:3 in reply to: ↑ 2 GavinCameron5 years ago

Replying to DD32:

Canonical is based upon your "Home" and "Site URL" options you set.

You need to set them to the publically-accessable name, NOT the private url.

Both "WordPress address (URL)" & "Blog address (URL)", which are the settings I think you are talking about are BOTH set to the correct externally accessible name. I don't have the internal name anywhere in my config.

comment:4 follow-up: DD325 years ago

I might've got those around the wrong way then.. Set them to the internal URL's, The Proxy should re-write them to the external address..

You can define them in your wp-config.php file as well if need be:

define('WP_SITEURL', "http://hostname/folder/");
define('WP_HOME', "http://hostname/");

The issue is that WordPress see's the URL's as "http://wordpressserver:1234/some-permalink/" which doesnt match "http://some-external-hostname.com/some-permalink/", which causes a redirect, etc.

comment:5 in reply to: ↑ 4 GavinCameron5 years ago

Replying to DD32:

I might've got those around the wrong way then.. Set them to the internal URL's, The Proxy should re-write them to the external address..

Setting these to the internal URL doesn't work either.

You can define them in your wp-config.php file as well if need be:

define('WP_SITEURL', "http://hostname/folder/");
define('WP_HOME', "http://hostname/");

Setting these still gives the same result.

The issue is that WordPress see's the URL's as "http://wordpressserver:1234/some-permalink/" which doesnt match "http://some-external-hostname.com/some-permalink/", which causes a redirect, etc.

Will commenting out

add_action('template_redirect', 'redirect_canonical');

actually cause an issue? Site seems to work correctly when it is commented out.

comment:6 DD325 years ago

No, It doesnt cause issue, Just removes the functionality of redirecting partial url's and allows content to be accessed from multiple urls'

Some canonical info: http://markjaquith.wordpress.com/2007/09/25/wordpress-23-canonical-urls/

A better way to disable it, A 1-line plugin: http://txfx.net/files/wordpress/disable-canonical-redirects.phps

comment:7 ryan5 years ago

  • Component changed from General to Canonical
  • Owner changed from anonymous to markjaquith

comment:8 Nicholas915 years ago

  • Milestone changed from 2.7.2 to 2.8

comment:9 Denis-de-Bernardy5 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.8 to 2.9

comment:10 Denis-de-Bernardy5 years ago

  • Priority changed from high to normal
  • Severity changed from critical to normal

comment:11 azaozz4 years ago

  • Milestone changed from 2.9 to Future Release

No patch.

comment:12 dd323 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Sites which use Loadbalancers/proxies should either configure the servers so that WordPress believes it's the front end server, or an addition should be made to wp-config.php (or sunrise, or similar) which mangles $_SREVER so WordPress thinks it is.

Note: See TracTickets for help on using tickets.