AJS.contextPath() returns undefined

I have Confluence set up behind a reverse proxy.
I redirect https://skowron.it/zbyl to http://localhost/zbyl

What I have done:

  1. I have installed evaluation version of Confluence 6.6.0 on Windows 10 64 bit. I have not installed any plugins.
  2. I've added proxyName="skowron.it" proxyPort="443" scheme="https" in server.xml
  3. I've set <Context path="/zbyl" ...> in server.xml
  4. I've set <property name="confluence.webapp.context.path">/zbyl</property> in confluence.cfg.xml
  5. I have changed Confluence's Base URL to https://skowron.it/zbyl

It mostly works.
However I get this message on each Confluence page I visit:

"Confluence's base URL is set to https://skowron.it/zbyl but you are accessing Confluence from https://skowron.itundefined."

I have managed to debug it to a point, where AJS.contextPath() function returns undefined.

As a result some features of Confluence don't work, because the browser sends requests to bad addresses, such as: "undefined/rest/webResources/1.0/resources" or "undefined/rest/analytics/1.0/publish/bulk".

Oddly enough when I view HTML source of the generated pages. there are 3 places with "context-path", and they all have valid value: "/zbyl".
And yet AJS.contextPath() returns undefined.

For completeness those 3 places are as follows:

<meta id="confluence-context-path" name="confluence-context-path" content="/zbyl">
<meta id="confluence-base-url" name="confluence-base-url" content="https://skowron.it/zbyl">
<meta name="ajs-context-path" content="/zbyl">
<meta name="ajs-base-url" content="https://skowron.it/zbyl">

I cannot find any workaround or solution for this problem.
There is however one post with similar symptoms (same broken links) here:

1 answer

0 votes
Ann Worley Atlassian Team Jan 02, 2018

Hi Zbigniew,

It sounds like the context path is set up correctly in Confluence, based on How to change the Confluence context path.

You didn't mention which reverse proxy you are using but the other case you reference is using NGINX so I am going to initially assume that's the proxy you are using.

Since you used proxyPort 443, it sounds like you are terminating SSL at the proxy. Please compare your NGINX configuration to this one, from: Running Confluence behind NGINX with SSL

server {
listen www.example.com:80;
server_name www.example.com;

listen 443 default ssl;
ssl_certificate /usr/local/etc/nginx/ssl/nginx.crt;
ssl_certificate_key /usr/local/etc/nginx/ssl/nginx.key;

ssl_session_timeout 5m;

ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location /confluence {
client_max_body_size 100m;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8090/confluence;
location /synchrony {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8091/synchrony;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
I look forward to hearing what you find.

Thanks for your reply.
It turned out that the reverse proxy was additionally set up to alter "Content-Security-Policy" and "Strict-Transport-Security" HTTP headers.
After removing settings related to that it all works fine.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

496 views 2 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you