Anyone have a working nginx.conf to proxy shiny-server?

1,693 views
Skip to first unread message

Joel M.

unread,
Jul 12, 2015, 2:22:08 AM7/12/15
to shiny-...@googlegroups.com
I've tried several permutations of a "location" block with "proxy_pass" in my nginx.conf file and, so far, I've been unsuccessful in proxying shiny server version 1.4.0.718 with nginx version 1.6.3 on CentOS 7.

Does anyone have an example that is known to work?

Thanks in advance.

Dean Attali

unread,
Jul 12, 2015, 6:36:41 PM7/12/15
to shiny-...@googlegroups.com
I'm using shiny server with nginx, but on Ubuntu 14.04
I got it to work nicely.  I have a tutorial on how to set up a shiny server on a virtual machine which and there's a section on configuring nginx it might be useful to you http://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/#reverse-proxy

Here's my nginx config file in case that helps

Joel M.

unread,
Jul 12, 2015, 10:06:54 PM7/12/15
to shiny-...@googlegroups.com
Thanks for the reply Dean.  And thank you too for the great tutorial.  (It also came up in my searches for info on configuring nginx to work with shiny server.)

So, I decided to just try your nginx.conf file pretty much verbatim (though I needed to add an "events { }" block and wrap the "server { }" block in an "http { }" block).  Restarted nginx, but no luck.

Just to make sure I'm not missing something obvious, I guess I should state what I expected would happen with your nginx.conf:
Without nginx, I am able to access shiny apps directly at port 3838.  For example I can successfully run the hello sample app at  http://10.211.55.6:3838/sample-apps/hello/ .

I expect with your nginx.conf, I should be able to run that same app via http://10.211.55.6/shiny/sample-apps/hello/  .
However, when I go to http://10.211.55.6/shiny/sample-apps/hello/ I get a "502 Bad Gateway" error from nginx.  (Previously, my attempts to access Shiny apps through nginx were resulting in "404 Not Found" errors.)

Also, I should mention that, just to be sure there wasn't something wrong with the networking config within the CentOS host, I installed the old Lynx browser and confirmed that I can access http://10.211.55.6:3838/sample-apps/hello/ .  I can also use Lynx to access it via http://127.0.0.1:3838/sample-apps/hello/ and http://localhost:3838/sample-apps/hello/ .

Out of curiosity, why does your nginx.conf file have only a "server { }" block and omit the "http { }" block, "events { }" block, etc.?   (I ask because those are the differences I had to introduce to get nginx to start.)

Thanks again.

Joel

Joel M.

unread,
Jul 12, 2015, 10:16:55 PM7/12/15
to shiny-...@googlegroups.com
Nevermind my last question. I see that example isn't intended to be the complete nginx.conf file.  I expect that it's "included" into the main nginx.conf file somewhere in its "http { }" block.  For example, with something like this  "include /etc/nginx/sites-enabled/*;".

Dean Attali

unread,
Jul 12, 2015, 10:17:13 PM7/12/15
to Joel M., shiny-...@googlegroups.com
I should make it clear that I'm not very knowledgeable with nginx and this kind of stuff - I just did what I had to do to get my setup working, but I don't know much outside of that :/
The file that I pointed you to is actually not the main nginx config file, it's `/etc/nginx/sites-enabled/default`.  The main nginx config file (at /etc/nginx/nginx.conf) has the events and http blocks, and it also includes this file. I should have probably made that clear earlier. Hopefully this helps, if not I'm really not the best person to help debug, I just thought if you followed exactly my directions maybe it'd work :)

--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/uLiguxpnm5k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/e2c88bbb-40f3-4793-bb9a-71d1487a6894%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joel M.

unread,
Jul 12, 2015, 10:21:10 PM7/12/15
to shiny-...@googlegroups.com, joe...@gmail.com
Oh, no worries.  Thanks so much for the reply.  It's great to have at least one working configuration as a reference.  I'll keep banging on it.  : )

Mitchell Gritts

unread,
Jul 11, 2016, 6:16:58 PM7/11/16
to Shiny - Web Framework for R
I was able to use Dean's `/etc/nginx/enabled-sites/default` to fix the issues I has having. I only needed to add these 3 lines from the shiny portion

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";Enter code here...

Joel M.

unread,
Jul 15, 2016, 11:45:36 AM7/15/16
to Shiny - Web Framework for R
Thanks for replying to this old thread Mitchell. Yeah, those are the same 3 critical lines I have in location blocks that pertain to Shiny apps for which nginx is acting as a reverse proxy server.  When I started this thread with a question, it was my initial attempt at a spike solution for a Shiny Server configuration (just kicking the tires to see if it could potentially work for me).  I'm not even sure now what the particular issue was for me at that time, though I do recall having to make a CentOS configuration change to allow for TCP connections from the host OS back to itself (i.e. nginx connection to Shiny Server running on the same host).
Reply all
Reply to author
Forward
0 new messages