Enhance yourpart-https.conf with improved WebSocket and API configurations

- Added www redirect to ensure consistent domain usage.
- Consolidated WebSocket upgrade conditions for clarity.
- Streamlined API request forwarding and fallback proxy settings for better organization and maintainability.
This commit is contained in:
Torsten Schulz (local)
2026-01-14 11:57:35 +01:00
parent 2bf949513b
commit d7c2bda461
2 changed files with 55 additions and 17 deletions

35
debug-websocket-headers.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
echo "=== WebSocket-Header Debug ==="
echo ""
echo "Prüfe Apache-Logs für WebSocket-Upgrade-Header..."
echo ""
# Prüfe die letzten 50 Zeilen des Access-Logs für /ws/ oder /socket.io/
echo "Access-Log Einträge für /ws/ und /socket.io/:"
sudo tail -50 /var/log/apache2/yourpart.access.log | grep -E "(/ws/|/socket.io/)" | tail -10
echo ""
echo "Prüfe Error-Log für WebSocket-Fehler:"
sudo tail -50 /var/log/apache2/yourpart.error.log | grep -iE "(websocket|upgrade|proxy)" | tail -10
echo ""
echo "=== Test mit curl ==="
echo ""
echo "Teste WebSocket-Upgrade für /ws/:"
curl -i -N \
-H "Connection: Upgrade" \
-H "Upgrade: websocket" \
-H "Sec-WebSocket-Version: 13" \
-H "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \
https://www.your-part.de/ws/ 2>&1 | head -20
echo ""
echo "=== Prüfe Apache-Konfiguration ==="
echo ""
echo "Aktive Rewrite-Regeln für WebSocket:"
sudo apache2ctl -S 2>/dev/null | grep -A 5 "your-part.de:443" || echo "VirtualHost nicht gefunden"
echo ""
echo "Prüfe, ob mod_proxy_wstunnel aktiviert ist:"
apache2ctl -M 2>/dev/null | grep proxy_wstunnel || echo "mod_proxy_wstunnel NICHT aktiviert!"

View File

@@ -18,32 +18,39 @@
FallbackResource /index.html FallbackResource /index.html
</Directory> </Directory>
# www Redirect (muss zuerst kommen, damit WebSocket-Regeln nicht beeinflusst werden)
RewriteEngine on
RewriteCond %{SERVER_NAME} =your-part.de
RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
# Proxy-Einstellungen # Proxy-Einstellungen
ProxyPreserveHost On ProxyPreserveHost On
ProxyRequests Off ProxyRequests Off
RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-Proto "https"
AllowEncodedSlashes NoDecode AllowEncodedSlashes NoDecode
# WebSocket-Upgrade mit RewriteRule (muss VOR ProxyPass stehen!)
# WebSocket-Upgrade für Socket.io
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/socket.io/(.*)$ "ws://localhost:2020/socket.io/$1" [P,L]
# WebSocket-Upgrade für Daemon
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/ws/(.*)$ "ws://localhost:4551/$1" [P,L]
# API-Requests an Backend weiterleiten # API-Requests an Backend weiterleiten
ProxyPass "/api/" "http://localhost:2020/api/" ProxyPass "/api/" "http://localhost:2020/api/"
ProxyPassReverse "/api/" "http://localhost:2020/api/" ProxyPassReverse "/api/" "http://localhost:2020/api/"
# WebSocket-Upgrade mit RewriteRule (muss VOR ProxyPass stehen!)
RewriteEngine on
# WebSocket-Upgrade für Socket.io
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} =upgrade [NC]
RewriteRule ^/socket.io/(.*)$ "ws://localhost:2020/socket.io/$1" [P,L]
# WebSocket-Upgrade für Daemon
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteCond %{HTTP:Connection} =upgrade [NC]
RewriteRule ^/ws/(.*)$ "ws://localhost:4551/$1" [P,L]
# HTTP-Proxy für Socket.io (Fallback für Polling) # HTTP-Proxy für Socket.io (Fallback für Polling)
ProxyPass "/socket.io/" "http://localhost:2020/socket.io/" ProxyPass "/socket.io/" "http://localhost:2020/socket.io/"
ProxyPassReverse "/socket.io/" "http://localhost:2020/socket.io/" ProxyPassReverse "/socket.io/" "http://localhost:2020/socket.io/"
# HTTP-Proxy für Daemon (Fallback, sollte eigentlich nicht benötigt werden)
ProxyPass "/ws/" "http://localhost:4551/"
ProxyPassReverse "/ws/" "http://localhost:4551/"
ErrorLog /var/log/apache2/yourpart.error.log ErrorLog /var/log/apache2/yourpart.error.log
CustomLog /var/log/apache2/yourpart.access.log combined CustomLog /var/log/apache2/yourpart.access.log combined
@@ -56,9 +63,5 @@
Include /etc/letsencrypt/options-ssl-apache.conf Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.your-part.de/fullchain.pem SSLCertificateFile /etc/letsencrypt/live/www.your-part.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.your-part.de/privkey.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.your-part.de/privkey.pem
# www Redirect
RewriteCond %{SERVER_NAME} =your-part.de
RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost> </VirtualHost>
</IfModule> </IfModule>