Configuration for running Apache and Shiny server on port 80 but using different virtual host name

4,969 views
Skip to first unread message

Marco Blanchette

unread,
Jun 25, 2014, 1:29:38 PM6/25/14
to shiny-...@googlegroups.com
Hi guys, 

Seems like this has been brushed before but I can't seem to be able to figure it out. I would like to use be able to run both apache and shiny server listening on port 80 but responding to different host name. mywebpage.domain.com being served by apache and myShinyApp.domain.com by shiny server. I tried to set the default apache virtual host port to something else than 80, but it still find other virtual hosts to serve a default page even though I have the following config for the shiny server. I understand that this is an apache config, but help would be greatly appreciated.


thanks

here is my shiny server config

# Instruct Shiny Server to run applications as the user "shiny"                                                                                                                                                         
run_as shiny;

# Define a server that listens on port 80                                                                                                                                                                             
server {
  listen 80;

  server_name myShinyApp.domain.com;

  # Define a location at the base URL                                                                                                                                                                                   
  location / {

    # Host the directory of Shiny Apps stored in this directory                                                                                                                                                         
    site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory                                                                                                                                                                   
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,                                                                                                                                             
    # an index of the applications available in this directory will be shown.                                                                                                                                           
    directory_index on;
  }
}

Sigbert Klinke

unread,
Jul 19, 2014, 3:36:57 PM7/19/14
to shiny-...@googlegroups.com
This will not work, you can not have two servers listen to same port. What you can do is:

1. Let Apache listen to Port 80 and the Shiny server to port 3838
2. Create your two virtual hosts mywebpage.domain.com and myShinyApp.domain.com in Apache
3. In Apache configure a proxypass rule such that all traffic to  myShinyApp.domain.com is redirected to localhost;3838 with

ProxyPass             / http://localhost:3838 
ProxyPassReverse / http://localhost:3838

I tried this approach, but http://myShinyApp.domain.com/test always delivered an error message 404. For some reason this address was not passed to the shiny server, but http://myShinyApp.domain.com/test/ worked :( Finally I decided to use directly http://mywebpage.domain.com:3838/test .

Marco Blanchette

unread,
Jul 21, 2014, 12:09:06 PM7/21/14
to shiny-...@googlegroups.com
Great!! That works!. 

What I did a bit different is

1) Set the location / directive in /etc/shiny-server/shiny-server.conf point to my app directory, have it listen to port 3838 and remove the server_name directive
2) then followed Sigbert suggestion
3) turn on mod_proxy and mod_proxy_http in apache (they are disabled in standard Ubuntu release)

Requesting http://myShinyApp.domain.com does the trick and starts my app.

Thanks Sigbert

Sigbert Klinke

unread,
Jul 22, 2014, 2:49:31 AM7/22/14
to shiny-...@googlegroups.com
Hi, do you have the problem with/without the trailing slash I mentioned? Sigbert

Marco Blanchette

unread,
Jul 26, 2014, 7:48:48 PM7/26/14
to shiny-...@googlegroups.com
I don't not sure why... Can you expand a bit on what the problem is? My server points to a single app... Maybe this makes a diff

carlos vargas

unread,
Aug 22, 2014, 1:00:54 PM8/22/14
to shiny-...@googlegroups.com
Dear Marco and Sigbert, thank you for this thread, this is exactly what I've been trying to do, however I'm unable to create Apache's virtual hosts. Can you explain the parameters you used with more detail please?

Sigbert Klinke

unread,
Aug 25, 2014, 3:48:05 AM8/25/14
to shiny-...@googlegroups.com
This was my last trial such that


<VirtualHost *:80>
    ServerAdmin ...
    ServerName my.domain.name.de

   
<Proxy /shiny/>
      Allow from localhost
   
</Proxy>

    ProxyPreserveHost On
    ProxyPass /shiny/ http://localhost:3838/
    ProxyPassReverse /shiny/ http://localhost:3838/    

    DocumentRoot /var/www
   
<Directory />
       ...
   
</Directory>
...
</VirtualHost>

As I wrote I had problems with trailing slahes when accessing a directory.

Marco Blanchette

unread,
Aug 25, 2014, 10:19:48 AM8/25/14
to shiny-...@googlegroups.com
Hi Carlos, what OS are you using, version? [the management of the apache server can vary widely]. Is it quite vanilla or heavily costumized?

Have you ever been able to create an apache virtual host? (Ie two hosts with different names pointing to the same IP but serving different content). I guess, this is probably where you want to start. There is a very good how to in the apache doc. But first before starting to tweak your server, you need to have two DNS entries pointing to the same adress (usually one A record and then a bunch of CNAME or ALIAS records).

Not sure at what level you are but if nothing of this make sense, you have a bit of reading before trying to implement a proxy server.

Let us know, we can probably help you or show you where to find Information.

Ivan Olier

unread,
Oct 16, 2014, 6:30:08 PM10/16/14
to shiny-...@googlegroups.com
Hi,
probably you have sorted this out but, just in case, you can add this:

RedirectMatch permanent ^/test$ /test/


Ivan

Gabriel Defagot

unread,
May 5, 2015, 8:42:22 AM5/5/15
to shiny-...@googlegroups.com
Hi ! I'm having trouble to configure shiny-server. What I want is that, if I got an App1 under /srv/shiny-server, I want to access it by shiny.mydomain.com/App1, but I got an error page.
What I did so far was: 
- install shiny-server
- run /sbin/service shiny-server start
- set the server ip and server name on the shiny-server.conf

Now, I know that I have to set a virtual host on apache, but I'm not sure of the configuration. Should I use the /srv/shiny-server as DocumentRoot? I need to set proxy as you do here to achieve what I want?
My virtual host is like this:

<VirtualHost *:80>
     ServerAdmin ....
     ServerName shiny.mydomain.com
     DocumentRoot /var/www/shiny/
</VirtualHost>

And my shiny-server.conf looks like this:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838 "serverIP";
  server_name "shiny.mydomain.com";
  # Define a location at the base URL
  location / {

    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.
    directory_index on;
  }
}



Thank you in advance

Mian Asbat Ahmad

unread,
Dec 15, 2016, 5:50:01 AM12/15/16
to Shiny - Web Framework for R
Here is what worked for me. 
my hostname on Centos 7 is rserver.example.com
I added the following lines to the end of my /etc/http/conf/httpd.conf

<VirtualHost *:80>
 ProxyPreserveHost On
 ProxyRequests Off
 ServerAlias rserver.example.com
</VirtualHost>

Restart httpd server i.e. systemctl restart httpd.server
Open firefox and type localhost or rserver.example.com
It will go directly to the hello app presented by shiny server

If you want to direct rserver.example.com/hello to your shiny app (assuming hello is the name of your app) then change ProxyPass and ProxyPassReverse in the above code to the following
Reply all
Reply to author
Forward
0 new messages