DidierMurilloF / FielDHub

FielDHub is an R Shiny design of experiments (DOE) app that aids in the creation of traditional, unreplicated, augmented and partially replicated (p-rep) designs applied to agriculture, plant breeding, forestry, animal and biological sciences.
https://didiermurillof.github.io/FielDHub/
Other
39 stars 20 forks source link

Running as Docker image on URL sub-path #44

Closed sebastian-raubach closed 7 months ago

sebastian-raubach commented 7 months ago

Hi there. I've been running FielDHub locally on my laptop for a while and now started looking into running a Docker image using your Dockerfile on a server.

I can make the application start up fine, but I run into issues with it running on a sub-path on my domain, so something like

https://test.domain.com/fieldhub

When I access the application on this path (using a reverse proxy), the app tries to load resources like JS and CSS files as well as images from https://test.domain.com/<filename> instead of https://test.domain.com/fieldhub/<filename>.

I currently cannot see a way to tell FielDHub to adjust those paths based on the folder it lives in. Is this something that is currently possible and if not, do you think you'll be able to add this in the future?

DidierMurilloF commented 7 months ago

Hi, could you please let me know which reverse proxy you're using (e.g., Nginx, Apache, etc.)? Knowing this will help me provide you with more specific assistance.

sebastian-raubach commented 7 months ago

Apache. This is basically what I've got:

ProxyPass        /fieldhub           http://internalserver:8963
ProxyPassReverse /fieldhub           http://internalserver:8963

Then the docker-compose.yml has this:

version: '3.3'
services:
    fieldhub:
        image: fieldhub:latest
        ports:
          - 8963:3838
        restart: always
        container_name: fieldhub
DidierMurilloF commented 7 months ago

Hello,

Based on the details you've provided, it looks like two main areas in your Apache configuration need adjustment to ensure your Shiny app runs correctly under the /fieldhub path and handles WebSocket connections properly. Here's an updated configuration that addresses these points:

<VirtualHost *:80>
    ServerAdmin webmaster@yourdomain.com
    ServerName yourdomain.com
    DocumentRoot /var/www/html

    # Enable WebSocket Connection for Shiny
    # Ensure mod_rewrite is enabled with "sudo a2enmod rewrite"
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/fieldhub/(.*) ws://internalserver:8963/$1 [P,L]

    # Reverse proxy configuration for fieldhub with the trailing slashes
    ProxyPass /fieldhub/ http://internalserver:8963/
    ProxyPassReverse /fieldhub/ http://internalserver:8963/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Key Adjustments:

  1. Trailing Slashes for ProxyPass Directives: It's important to include trailing slashes (/fieldhub/) in your ProxyPass and ProxyPassReverse directives to ensure that the path is correctly matched and rewritten. This helps Apache to properly forward the requests to your Shiny application running in Docker.

  2. WebSocket Support: Your initial configuration needed to account for WebSocket connections, which are crucial for interacting with Shiny applications. The added RewriteRule with conditions for WebSocket (ws://) ensures that WebSocket traffic is correctly proxied to the Shiny app.

Applying the Configuration:

After updating the Apache configuration, remember to reload Apache to apply the changes:

sudo systemctl reload apache2

Please enable the required Apache modules (mod_proxy, mod_proxy_http, mod_rewrite, and mod_proxy_wstunnel for WebSocket support).

This configuration should help the FielDHub app to operate smoothly under the specified subpath with full WebSocket support.

I hope this helps!

sebastian-raubach commented 7 months ago

That seems to have done the trick. Wasn't aware Shiny uses Websocket. The trailing slashes haven't been necessary for all the other things we run, but seem to be required here.

Thanks!

sebastian-raubach commented 7 months ago

I've got a few more questions but I feel GitHub issues isn't the right place for them. Do you have a contact email address for FielDHub?

DidierMurilloF commented 7 months ago

It's nice that the Apache setup also worked for you. I tested it before.

Sure, you can email me at didier.murilloflorez[at]ndsu.edu