Last modified: 2013-10-23 18:17:33 UTC
I have set $wgServer = ''; in order to run my wiki behind an Apache reverse proxy and in order to support port forwarding when accessing the wiki via SSH on another port than 80 (e.g. local port 8000 forwarded to 80). This way I avoid sending an absolute URL back to the client for certain actions (like login/logout, search). So far that works since years even though the Location header sent to the browser is relative (might violate the standard, but works with major browsers). But since 1.18 I get PHP notices when $wgServer is set to such an empty string: ########### PHP Notice: Undefined index: scheme in /srv/www/htdocs/mediawiki-1.18.0/includes/GlobalFunctions.php on line 572, referer: http://xxx PHP Notice: Undefined index: scheme in /srv/www/htdocs/mediawiki-1.18.0/includes/GlobalFunctions.php on line 574, referer: http://xxx ########### This is due to new code for handling the URL. Therefore, I would like to ask adding isset() checks to GlobalFunctions.php before $bits['scheme'] is accessed.
MediaWiki really, really doesn't expect $wgServer to be empty... not sure what other problems might crop up. This particular part looks like it might be fixed by merging r94352 (though whether that'd break other things after I don't know).
Well, I understand that $wgServer to be empty is not typical and should hopefully never happen. But that was the only way to support my corporate wiki in a quite complex network scenario. Maybe there is another solution by magic configuration, please let me explain: 1) My wiki must be accessed from two different interfaces. Access via interface 1 is via a reverse proxy (Apache). Interface 2 is via direct connected hosts on the same LAN (either by FQDN according to local hosts file or IP address). Some people also access the wiki on interface 2 by port forwarding using something like "ssh -L 8000:127.0.0.1:80". 2) Due to the reverse proxy I can't keep $wgServer auto-detected, since that results in sending a wrong (internal) URL back to the clients on interface 1. Therefore, I need to set $wgServer manually. 3) If I set $wgServer to either 'http://myproxydomain.de' or '//myproxydomain.de' I get the following results: a) Access via reverse proxy on interface 1 works, since myproxydomain.de is fully routed from in front of the reverse proxy. b) Access via interface 2 (LAN) works if I add myproxydomain.de to local hosts file (no DNS). Access on IP address (http://<IP>) doesn't work due to redirects (see c), but that's ok for me. c) But if I access via interface 2 by SSH port forwarding, e.g. as http://myproxydomain.de:8000, I am often redirected to a "HTTP Location" that does NOT contain port 8000, so the client fails to load the page. This happens for example after login or when I just access http://myproxydomain.de:8000/wiki/index.php which redirects to http://myproxydomain.de/wiki/index.php/Main_Page. Strange is, that when I keep $wgServer auto-detected these redirects contain the port 8000. So, scenario 3c works if $wgServer is auto-detected, but then access via interface 1 (reverse proxy) doesn't work. 4) If I set $wgServer to be empty all above scenarios work (even access on pure IP address URL), since the HTTP Location is always relative. Question: How can I set $wgServer (or other variables) to solve problem 3c ?
Whenever the request comes from localhost (i.e. it comes from SSH), you could set wgServer to auto detect, that should detect the 8000 port. Leave wgServer hardcoded in other cases (i.e. to 'http://myproxydomain.de/ ).
(In reply to comment #3) Yes, of course. But I need to support both scenarios at the same time. Or can $wgServer be set dynamically dependent on which interface the request comes in?
You can look at the remote client address with $_SERVER['REMOTE_ADDR'] , something like: if( preg_match( $_SERVER['REMOTE_ADDR'], '^192\.168\.0\.' ) { // local LAN clients } else if ( $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) { // localhost! } else { // external access? }
(In reply to comment #5) > You can look at the remote client address with $_SERVER['REMOTE_ADDR'] , > something like: > > if( preg_match( $_SERVER['REMOTE_ADDR'], '^192\.168\.0\.' ) { > // local LAN clients > > } else if ( $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) { > // localhost! > > } else { > // external access? > > } Ok. Good idea. Then I would need to put that kind of code to LocalSettings.php and set $wgServer for each case differently. I'll give that a try. Thank you.
WONTFIXING this, but please do not let that stop any additional questions you have.
Based on the suggestion from "hashar" I have fixed my config issue with the following code in LocalSettings.php: ################# if (preg_match('/^10\.2\.175\./',$_SERVER['REMOTE_ADDR'])) $wgServer = 'http://myproxydomain.de'; ################# The reverse proxy source address is within 10.2.175 range. So, if the client comes from that network $wgServer is set to the "external" URL (with fixed port). In all other cases the default is used (auto-detection) which works fine for all other scenarios (incl. port forwarding). Thanks again for that hint (which was quite obvious).
Well done user66! Enjoy your MediaWiki installation.