You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hello, Community!
Having spent a couple of days trying to get NGINX and Confluence work together as expected I decided to share my experience with you.
We want to use our Confluence as a public website so we have some SEO considerations such as human-friendly URLs. Yes, I know that there is guidance for making clear URLs without "?pageId"-thing but, unfortunately, this is not our case as we don't use English for our website.
In the config example below there's also a "proxy_pass" section. We use NGINX also as a reverse proxy to change the default port 8090 to standard 80 (as described here)
So, here we go:
server {
listen www.example.com:80;
server_name www.example.com;
location / {
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;
root /opt/atl/instd/atlassian-confluence-6.8.2/confluence/;
location /pages {
if ($args ~ pageId=xxxxxx) {return 301 /your-pretty-url1-goes-here;}
if ($args ~ pageId=yyyyyy) {return 301 /your-pretty-url2-goes-here;}
...
}
rewrite ^/your\-pretty\-url1\-goes\-here?$ /pages/viewpage.action?pageId=xxxxxx break;
rewrite ^/your\-pretty\-url2\-goes\-here?$ /pages/viewpage.action?pageId=yyyyyy break;
...
proxy_pass http://localhost:8090/;
}
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";
}
}
Let me explain what do we have here:
1.
root /opt/atl/instd/atlassian-confluence-6.8.2/confluence/;
changes the root for nginx so that it looks for pages from there. The default "/usr/share/nginx/html/" results in "failed (2: No such file or directory)".
2.
location /pages {
...
}
I choose "/pages" as a nested location, because all of our anonymously accessed pages URLs look something like:
www.example.com/pages/viewpage.action?pageId=xxxxxx
3.
if ($args ~ pageId=xxxxxx) {return 301 /your-pretty-url1-goes-here;}
redirects the request with the particular pageId to your custom URL
4. And, finally
rewrite ^/your\-pretty\-url1\-goes\-here?$ /pages/viewpage.action?pageId=xxxxxx break;
rewrites back to the original source page.
The main advantage for us here is that pages diplayed with normal, human-readible URLs all the time whether it's an external link with friendly URL already in place (www.example.com/your-pretty-url1-goes-here) or an internal Confluence link. All of them are displayed correctly.
There are also some drawbacks, of course.
The first one is that you have to manually edit the nginx config file for every new page you create. In our case it's not so awful as our website is going to be static.
The second one is that I don't really know how search engines would react to such 301 redirects of ours and wouldn't it be SEO-unfriendly.
So, that all for now. If someone notices any mistakes or has any suggestions, you are most warmly welcome to the discussion :)
Thank you for your attention.