Question

custom directory for rstudio server on droplet

Posted August 14, 2020 80 views
Apache

I have a website that is currently working (say, example.com). I have set up my virtual host file (example.conf) so that port 80 points to example.com:

<VirtualHost *:80>

    ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com
    DocumentRoot /var/www/example

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


RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

I have also set up ssl in a file called example-le-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com
    DocumentRoot /var/www/example

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

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>

So far, so could. Now, I have installed a shiny server (which defaults to port 3838). I can access that by typing example.com:3838, but I want to access it by typing example.com/shiny. I read the instructions on how to set up a reverse proxy. In there, it says to replace 000-default.conf with:

<VirtualHost *:80>
    ProxyPreserveHost On

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>

Of course, in my case, I assume I would do 3838 instead of 8080:

<VirtualHost *:80>
    ProxyPreserveHost On

    ProxyPass /shiny/ http://127.0.0.1:3838/
    ProxyPassReverse /shiny http://127.0.0.1:3838/
</VirtualHost>

No luck. example.com/shiny can’t be found.

So, I change the ip address to my site’s url:

<VirtualHost *:80>
    ProxyPreserveHost On

    ProxyPass /shiny/ http://example.com:3838/
    ProxyPassReverse /shiny http://example.com:3838/
</VirtualHost>

Still no luck, so I try my ip address:

<VirtualHost *:80>
    ProxyPreserveHost On

    ProxyPass /shiny/ http://[some ip address]:3838/
    ProxyPassReverse /shiny http://[some ip address]:3838/
</VirtualHost>

Still no luck. So I think that maybe I need to change example.conf instead of 000-default.conf:

<VirtualHost *:80>

    ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com
    DocumentRoot /var/www/example

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


RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

**    ProxyPreserveHost On

    ProxyPass /shiny/ http://[some ip address]:3838/
    ProxyPassReverse /shiny http://[some ip address]:3838/**

</VirtualHost>

Here I also tried the ip address, 127.0.0.1, and example.com. No luck.

What am I missing?

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi there,

I could suggest a few things:

  • First make sure that you have the required modules enabled, to check that run the following command:
  • apachectl -M | grep proxy
  • If you already have the modules enabled, as you already mentioned, move the proxy rules to your 000-default.conf Vhost. That way you should be able to access the proxy rule via http and your domain name.

  • If you want to be able to access the proxy rules via https, you need to add the proxy rules to your SSL Vhost as well and in addition add the following rule:

SSLProxyEngine on

If this is still not working, make sure to check your Apache error log:

  • sudo tail -100 /var/log/apache2/error.log

Regards,
Bobby

Submit an Answer