2

I have a Ubuntu 18.4 LTS server running OpenCPU, and am able to run the application myapp by pointing my browser to the address http://myip/ocpu/library/myapp/www/. I wish to make the app available via the domain name mydomain.name, and have set up DNS records to point to myip.

On the server side, I created a file /etc/apache2/sites-available/myapp.conf, which looks like

<VirtualHost *:80>
    ServerName mydomain.name
    DocumentRoot /ocpu/lib/myapp/www
    LogLevel info
    ErrorLog /var/log/myapp/apache_error.log
    CustomLog /var/log/myapp/apache_access.log combined
</VirtualHost>

However, sudo systemctl reload apache2 throws an error since it cannot find the documentRoot /ocpu/lib/myapp/www. In fact, there is no directory ocpu on the server.

I suspect that I need to set up a .conf file in /etc/opencpu/server.conf.d, but the structure of those files look very different from myapp.conf as given above, and I do not see an entry for a ServerName.

How do I redirect mydomain.name to http://myip/ocpu/library/myapp/www/?

Stef van Buuren
  • 348
  • 1
  • 10
  • Changed DocumentRoot to `/usr/local/lib/R/site-library/myapp/www`, added log files, reloaded and made `www-data` owner of `/usr/... /www` directory. Now getting "You don't have permission to access / on this server" – Stef van Buuren May 26 '19 at 10:29
  • Another failed attempt: Copy the contents of `/usr/local/lib/R/site-library/myapp/www` into `/var/www/myapp`. The page now loads, but the `openCPU` functionality disappears, probably because of cross-posting. – Stef van Buuren May 27 '19 at 20:56

1 Answers1

4

If the site is available through http://myip/ocpu/library/myapp/www/ but should be available through http(s)://mydomain.name you can simply create a proxy entry in your apache2 configuration like this:

<VirtualHost *:80>
    ServerName mydomain.name

    ProxyPreserveHost On
    ProxyPass "/" "http://myip/ocpu/library/myapp/www/"
</VirtualHost>

Note: You may have to enable the proxy module(s): sudo a2enmod proxy & sudo a2enmod proxy_http

This will serve the website http://myip/ocpu/library/myapp/www/ on mydomain.name.

Make sure to restart apache2 (sudo service apache2 restart) after editing the configuration and enabling the module(s).

Sources: https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension

Marvin Klar
  • 1,869
  • 3
  • 14
  • 32
  • Changed it according to your recommendation. When I now enter `mydomain.name` in the browser, the server becomes fully unresponsive, and I need to reboot the server from the AWS control panel. Could there be an endless loop here? – Stef van Buuren Jun 04 '19 at 19:50
  • If you have other configurations active, a loop can occur. Check your apache2 logs. There will be the same message multiple times, if it's a loop. Otherwise the site may be broken. Or the site tries to redirect you to `http://myip/ocpu/library/myapp/www/`, which is redirected to `mydomain.name` resulting in a endless loop. Can you configure the sites `webroot` in any configuration of the software? – Marvin Klar Jun 05 '19 at 07:13