1

nginx config:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl_certificate /path/to/tls/tls.crt;
    ssl_certificate_key /path/to/tls/tls.key;
    
    server_name the.domain.tld;
    
    location / {
        proxy_pass http://localhost:5001; 
    }

    location /api/socket {
        proxy_pass http://localhost:5001/api/socket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }
    
}

apache config:

<VirtualHost *:443>
        ServerName the.domain.tld

        ProxyPass / http://localhost:5001/
        ProxyPassReverse / http://localhost:5001/
        ProxyPass /api/socket http://localhost:5001/api/socket/
        ProxyPassReverse /api/socket http://localhost:5001/api/socket/

        RewriteEngine on

        RewriteCond %{HTTP:Upgrade} websocket [NC]
        RewriteCond %{HTTP:Connection} upgrade [NC]
        RewriteRule /(.*) "ws://localhost:5001/$1" [P,L]

        ProxyPreserveHost On
        ProxyAddHeaders On
        RequestHeader set X-Forwarded-Proto "https"

        SSLCertificateFile /path/to/tls/tls.crt
        SSLCertificateKeyFile /path/to/tls/tls.key

        SSLProxyEngine On
</VirtualHost>
vvvvv
  • 175
  • 8
TREX
  • 21
  • 3
  • 1
    What is the problem you are having? – Michael Hampton Sep 28 '21 at 12:40
  • The website redirection works if I'm using nginx reverse proxy. However, when I switch to apache2, the website doesn't redirect me. – TREX Sep 28 '21 at 13:15
  • Huh? I don't see any redirects in either configuration. Did you omit some part of the configuration, or are you talking about something else? – Michael Hampton Sep 28 '21 at 13:19
  • I'm following this guide on GitHub. However, I can't find a guide on apache reverse proxy config. https://github.com/varbhat/exatorrent/blob/main/docs/deploy.md#reverse-proxy – TREX Sep 28 '21 at 13:40
  • wh, do you want to switch? Use nginx in front off and use apache in the background. it is a common used practice – djdomi Oct 09 '21 at 19:45

1 Answers1

1

Solved! All I had to do was to enable the websocket module using sudo a2enmod proxy_wstunnel.

TREX
  • 21
  • 3