There’s an issue with the panel on Kirby 2.5.8 when using it behind a proxy, even when the appropriate headers are passed through the proxy (X-Fowarded-Host
and X-Forwarded-Port
). Specifically, the panel will log me out on when clicking certain links, redirect me to the wrong URL (127.0.0.1:8080
), and the “Your site’s URL” widget shows the wrong address (127.0.0.1:8080
).
My Setup
I’m using browser sync to enable live reloading during development. This works great with Kirby proper, no issues on page URLs, but the panel is failing to pick up on the correct host. Browser sync, by default, is running on port 3000
and my PHP server is at 8080
(I’m using the builtin PHP dev server, php -S 127.0.0.1:8080
). I access my site locally at http://localhost:3000
(through browser sync), but the panel is picking up the address as http://127.0.0.1:8080
, even after verifying that the X-Fowarded-*
headers are being passed to the server appropriately. The headers look like the following after adding dump(server::get())
to my home template:
Array
(
[DOCUMENT_ROOT] => <omitted>
[REMOTE_ADDR] => 127.0.0.1
[REMOTE_PORT] => 49513
[SERVER_SOFTWARE] => PHP 7.1.7 Development Server
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_NAME] => 127.0.0.1
[SERVER_PORT] => 8080
[REQUEST_URI] => /
[REQUEST_METHOD] => GET
[SCRIPT_NAME] => /index.php
[SCRIPT_FILENAME] => <omitted>/index.php
[PHP_SELF] => /index.php
[HTTP_X_FORWARDED_HOST] => localhost:3000 // This seems correct
[HTTP_X_FORWARDED_PROTO] => http
[HTTP_X_FORWARDED_PORT] => 3000 // Same with this
[HTTP_X_FORWARDED_FOR] => ::1
[HTTP_COOKIE] => <omitted>
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.9
[HTTP_ACCEPT_ENCODING] => identity
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
[HTTP_USER_AGENT] => <omitted>
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_CONNECTION] => close
[HTTP_HOST] => 127.0.0.1:8080
[REQUEST_TIME_FLOAT] => 1515183940.2791
[REQUEST_TIME] => 1515183940
[argv] => Array
(
)
[argc] => 0
)
Browser Sync Config
As an FYI for those setting up browser sync, which there seems to be a few issue on this forum, you should make sure to configure browser sync to pass the X-Forwarded-*
headers with the following:
"proxy": {
"target": "127.0.0.1:8080",
"proxyOptions": {
"xfwd": true
}
}
Likewise I’ve had success with the following file watch patterns for typical development:
"files": [
"assets",
"content",
"site/snippets",
"site/templates"
]
Work Around
I’ve found that configuring the url (c::set('url', 'http://localhost:3000');
) in the config will solve the issue, but it’s not ideal. Mostly because this must be placed in the config.php
not a config.localhost.php
(because of the aforementioned problem, the panel seems to ignore the localhost config). I believe it’s best that config.php
represent a production environment and a localhost config should override for development.
Ideally the panel, like Kirby, should be able to pick up on the X-Forwarded-*
headers and use that for the site base URL. There’s a few issues related to proxying and browser sync, but I can’t seem to synthesize a solution besides manually setting the url
in config.php
.
Has anyone else had this problem? Are there any other thoughts on how to fix this issue? Is this indeed a bug in the panel?
Thanks in advance for any assistance!
Update
It appears that the panel URLs whenever a page first loads are correct (they are http://localhost:3000
). In other words, if I go directly to any page in the panel, the URLs are correct. However, if I click on any link on the page, the subsequent page has the incorrect URLs (http://127.0.0.1:8080
). It appears that there is a distinction between how the PHP backend renders a panel page (from a full refresh) and how the JS frontend will render a page (subsequent navigation).
Hm, or perhaps a difference between how the proxy handle an XHR request vs a document request?
Update 2
Using MAMP with browser sync, or accessing the panel directly the the PHP server seem to work flawlessly. The issue is specifically the panel + browser sync + the PHP dev server.