snapdrop icon indicating copy to clipboard operation
snapdrop copied to clipboard

Creating selfhosted with apache

Open jonathan-dejong opened this issue 3 years ago • 3 comments

Hi! I've got a digitalocean droplet where I thought I'd try and get snapdrop running selfhosted. It's running apache and are hosting ~5 sites already (really light traffic).

I've been trying to get snapdrop up and running on it using Ubuntu 18.04 + Apache but I am stuck on modifying the nginx config to apache which I think is the problem I have left.

What I've done

  • Created a subdomain (let's call it snapdrop.mydomain.dev) and pointed it to www/snapdrop.mydomain.dev
  • Created an let's encrypt cert for it (must with .dev domains)
  • Git clones the repo into the root folder.
  • Ran npm install on the server folder.
  • Setup a service for it (that works)
[Unit]
Description=Snapdrop Service
After=network.target

[Service]
Type=simple
User=www-data
Group=www-data
Restart=on-failure
WorkingDirectory=/www/snapdrop.mydomain.dev/server
ExecStart=/usr/bin/node index.js

[Install]
WantedBy=multi-user.target
  • Created a new apache site config trying to recreate the important parts from this nginx conf https://github.com/RobinLinus/snapdrop/issues/266

My snapdrop instance is seen, I can navigate to it on https etc. etc. but the websocket can't connect. Here's my apache config atm:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin [email protected]
        Servername snapdrop.mydomain.dev
        DocumentRoot /var/www/snapdrop.mydomain.dev/client/

        <Directory /var/www/snapdrop.mydomain.dev/client/>
          Options indexes FollowSymLinks
          AllowOverride All
          Require all granted
        </Directory>

        <Proxy *>
          Order deny,allow
          Allow from all
        </Proxy>

        SSLEngine on
        SSLProxyEngine on
        ProxyRequests On
        ProxyPreserveHost On

        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/snapdrop.mydomain.dev/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/snapdrop.mydomain.dev/privkey.pem

        <Location snapdrop.mydomain.dev/server>
          proxyPass https://snapdrop.mydomain.dev:3000 connectiontimeout=300 timeout=300 Keepalive=On
          proxyPassReverse https://snapdrop.mydomain.dev:3000
          RequestHeader set Connection "upgrade"
          RequestHeader set Upgrade $http_upgrade
          RequestHeader set X-forwarded-for $remote_addr
          #REMOTE_ADDR
        </Location>

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

and here's the log I get on the snapdrop PWA, the interesting part is the one with the websocket, the rest occurs for snapdrop.net as well. snapdrop.mydomain.dev-1620627663639.log

I'd be super grateful for any help, I'm not great at servers but I'm learning as I go :) If I get this up and running I'll post a HOW TO guide back here.

jonathan-dejong avatar May 10 '21 06:05 jonathan-dejong

If I check out the request headers of the Webrtc a few seems set but it's not by my <Location> directive. If I change a value in there nothing changes.

Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,sv;q=0.7
Cache-Control: no-cache
Connection: Upgrade
Host: snapdrop.mydomain.dev
Origin: https://snapdrop.mydomain.dev
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: 8y4DJ6ZhdImhLFF0mVoU/A==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.86 Safari/537.36

jonathan-dejong avatar May 10 '21 06:05 jonathan-dejong

I use nodejs version and the following config works for me

Define pport 3001 RewriteEngine On RewriteCond %{HTTP:CONNECTION} Upgrade [NC] RewriteCond %{HTTP:Upgrade} =websocket [NC] RewriteRule /(.) ws://localhost:${pport}/$1 [P,L] RewriteCond %{HTTP:Upgrade} !=websocket [NC] RewriteRule /(.) http://localhost:${pport}/$1 [P,L] ProxyPassReverse / http://localhost:${pport}/

quanltt avatar Oct 11 '22 05:10 quanltt

This is my apache-config, which is working, except the "X-Forwarded-For-Part" You also have to enable proxy_http, proxy, proxy_wstunnel with a2enmod.

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /snapdrop/(.*) ws://localhost:8080/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /snapdrop/(.*) http://localhost:8080/$1 [P,L]

ProxyPass               /snapdrop/     http://localhost:8080/
ProxyPassReverse        /snapdrop/     http://localhost:8080/
ProxyPass               /snapdrop/     ws://localhost:8080/

<Proxy https://localhost:8080/>
    AllowOverride None
    Order allow,deny
    Allow from all
</Proxy>

Tone866 avatar Oct 15 '22 15:10 Tone866