Create custom links for several oTree installations hosted on the same server

112 views
Skip to first unread message

Rok

unread,
Dec 25, 2020, 1:23:52 PM12/25/20
to oTree help & discussion
Hello,

I have several oTree installations on my ubuntu server, which I set up like suggested in https://otree.readthedocs.io/en/latest/server/ubuntu.html#sharing-a-server-with-other-otree-users.

Each is accessed with a different port, for example: my.page:8101, my.page:8102, etc... They all work without problems.

Now I am trying to make the links more human readable, for example: my.page/server1, my.page/server2 etc...

I have attempted this by using Nginx as a reverse proxy. I have tried to approach this in a way a few different tutorials suggest, where the most relevant one seems to be this one: https://gist.github.com/soheilhy/8b94347ff8336d971ad0

When I set up the reverse proxy and visit the new link, (eg. my.page/server1) two things seem to happen:
  1. I am briefly redirected to the correct page: my.page:8101 (sometimes if the browser lags a bit i can see one frame of this page, otherwise i'm just guessing it happens, because of number 2: )
  2. this page then redirects me to the /demo subpage, but instead of redirecting me to the my.page:8101/demo subpage, I am redirected to the my.page/demo subpage, and get a 404 error.
I can't seem to get around the problem number two, even following tutorials that explicitly seem to offer help solving that exact problem.

If anyone has any experience setting up the servers like I described I have to, I'd be happy for the input and suggestions.

Rok

Chris @ oTree

unread,
Dec 25, 2020, 1:26:20 PM12/25/20
to oTree help & discussion
I think it's better to use different subdomains, like server1.my.page.

Rok

unread,
Dec 25, 2020, 4:47:45 PM12/25/20
to oTree help & discussion
Thank you for the quick answer. Subdomains seem like a great alternative! 

Do you have any suggestions how I should approach this; solutions like nginx or is this something django can handle?

Best Regards and Happy Holidays,
Rok

Chris @ oTree

unread,
Dec 25, 2020, 11:55:18 PM12/25/20
to Rok, oTree help & discussion
I think you would need to use something like nginx. 

Sent from my phone

On Dec 26, 2020, at 5:47 AM, Rok <fish.mi...@gmail.com> wrote:

Thank you for the quick answer. Subdomains seem like a great alternative! 
--
You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/S9IilBgV0U0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/c6a76dce-a04f-43c8-8f74-aeeeabd1173fn%40googlegroups.com.

Rok

unread,
Mar 3, 2021, 6:22:22 AM3/3/21
to oTree help & discussion
For anyone else trying to set up multiple servers with nginx serving as reverse proxy:

I ended up using the subdomains like Chris suggested. The nginx config for each otree server is as follows:

If you have for example one of your otree servers running on page.com:8002, and would like them to run on otree1.page.com, you would use the following config:

server {
listen 80;
server_name otree1.page.com;

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;

proxy_pass http://localhost:8002;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

If you want to set up multiple subdomains for multiple servers, just copy the above code for every server, changing the bolded parts.

Important: Make sure you actually have DNS redirecting all subdomains to your server (page.com), otherwise this will obviously not work. I spent more time than I'd like to admit debugging my server while the problem was with my DNS redirects.

Good luck. :)

Rok
Reply all
Reply to author
Forward
0 new messages