Zugriff auf FHEM über das Interne!...

Begonnen von moonsorrox, 22 Oktober 2017, 12:19:47

Vorheriges Thema - Nächstes Thema

moonsorrox

Ich möchte mit Hilfe eines Apache und einer zusätzlichen DDNS Domain auf mein FHEM über das Internet zugreifen. Nutzen möchte ich dazu das letsencrypt Zertifikat.

Da dies nicht so einfach ist - zumindest nicht für mich - eröffne ich hier mal diesen Beitrag, über jede weitere Hilfe bin sehr dankbar, da dieses für mich bisher absolutes Neuland war und ist.

Evtl. hilft das hier ja auch noch einigen anderen..
Angelehnt an einen Beitrag aus dem Internet stelle ich das hier einmal ins Forum.
Ich habe die Einrichtung weitestgehend nachvollziehen können aber dennoch kommen am Ende einige Fehlermeldungen und somit erhalte ich ein weiße Seite ohne Möglichkeit des Einloggens.

Was habe ich bisher gemacht, ich habe mich vollkommen nach dem Beitrag von Matthias Kleine gerichtet. Bin dabei bis kurz vor die Einrichtung des Cronjob gekommen mit eben einigen Fehlermeldungen.

Ein netter User hat mir schon per PN einige Hinweise gegeben, welche ich aber bisher noch nicht umgesetzt habe.
Wenn ich etwas mehr Zeit habe werde ich suchen da mein Dell T20 mit Proxmox noch in der Testphase ist und ich hier immer die neuen FHEM Erkenntnisse ausprobiere bis ich sie ins Produktiv System übernehme...


ZitatIch habe heute nochmals eine Installation auf meinem Proxmox Server in einem Container gemacht.
Ich komme bis zu dem Punkt und habe hier 2 Fehler, einmal in der apache2.conf Datei und dann mit dem include Pfad, diese Datei gibt es dort gar nicht.

Hier mal die Fehler:

root@FHEM-Server:/etc/apache2/sites-enabled# apachectl configtest
apache2: Syntax error on line 219 of /etc/apache2/apache2.conf:

an der Stelle steht im Original:
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

hier habe ich einfach meine Seite eingetragen, aber in beiden Fällen meckert er rum- was steht da bei euch drin

Syntax error on line 14 of /etc/apache2/sites-enabled/xxxmeinexx.de.conf: Could not open configuration file /etc/letsencrypt/options-ssl-apache.conf: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.

Wo befindet sich eigentlich die Apache error log Datei.?

Wo sich die error.log befindet weiß ich jetzt, zumindest wenn es die error.log.1 ist.
Nachtrag: komischer Weise heißt diese Logdatei auf meinem Produktiv System error.log.1
auf meiner Virtualmaschine ganz normal error.log, naja egal -wollte ich nur erwähnen

Das erst einmal zu der Problematik.
Intel-NUC i5: FHEM-Server 6.1 :: Perl v5.18.2

Homematic: HM-USB-CFG2,HM-CFG-LAN Adapter, HM-LC-BL1-FM, HM-LC-Sw1PBU-FM, HM-LC-Sw1-PI-2, HM-WDS10-TH-O, HM-CC-TC, HM-LC-SW2-FM

eisi

Zitat
>root@FHEM-Server:/etc/apache2/sites-enabled# apachectl configtest
>apache2: Syntax error on line 219 of /etc/apache2/apache2.conf:

>an der Stelle steht im Original:
># Include the virtual host configurations:
>IncludeOptional sites-enabled/*.conf

Das sollte auch so bleiben.
Normalerweise kommt deine Config in:
"/etc/apache2/sites-available" und MUSS! die Endlung .conf haben.
Dann wird ein Symlink (ln -s) dieser Configdatei in:
"/etc/apache2/sites-enabled" erstellt.
Dann wird der Apache neugestartet.
Einfacher kannst du es dir machen, wenn du die Configdatei direkt in
"/etc/apache2/sites-enabled" kopierst und dann die ursprüngliche Zeile in der Config wiederherstellst:
IncludeOptional sites-enabled/*.conf
Die bewirkt, dass die Configdateien in diesem Verzeichnis eingebunden werden.

Zitat
>Syntax error on line 14 of /etc/apache2/sites-enabled/fhem.resse-hausautomation.de.conf: Could not open configuration file /etc/letsencrypt/options-ssl-apache.conf: No such file or directory
Das File oder den Pfad gibt es nicht.
Also die Fehlersuche würde ich folgermaßen machen:

cd /etc

Wenn er nicht meckert dann:

cd /etc/letsencrypt/

Wenn er meckert, gibt es den Pfad letsencrypt in etc nicht.
Meckert er nicht, kann es nur noch sein, dass die Datei falsch geschrieben ist.

Mach einfach ein ls in dem Pfad:
ls /etc/letsencrypt/
Dann siehst du, welche Dateien sich dort befinden.

Zitat
Wo befindet sich eigentlich die Apache error log Datei.?

Meistens in /var/log/apache2

LG,
Ingo
3 x Rasp mit fhem 5.8 | 1 Rasp mit Kodi |1x Cube | 15 x MaxLan Thermostate und 18 Fensterschalter | 30 WLAN Schalter Sonoff | Diverse Sensoren mit Arduino | Tablet mit FTUI 2.6

erdo_king

Ich möchte dir hierzu einmal meine Lösung vorstellen:

Ich habe einen Raspberry Pi zu Hause laufen und einen Linux-Server mit Apache im Internet (also wie du ;) ... Tatsächlich mit Proxmox als unterbau, der Apache läuft bei mir in einem LXC Container ...
Der RasPi baut einen konstanten SSH-Tunnel auf, der den Port 8083 auf den Server tunnelt, der Apache greift anschließend per mod_proxy_http darauf zu...

Ich tunnel Port 8083 und 22 um an den RasPI zu kommen

/usr/local/bin/reconnect_ports.sh
#!/bin/bash

PORTS="7022:localhost:22 8083:localhost:8083"


for port in $PORTS; do

        PORT_REMOTE=$(echo $port |cut -f 1 -d ':')
        HOST_LOCAL=$(echo $port |cut -f 2 -d ':')
        PORT_LOCAL=$(echo $port |cut -f 3 -d ':')

        PS_COUNT=$(ps aux | grep "$PORT_REMOTE:$HOST_LOCAL:$PORT_LOCAL" | grep -v "grep" | wc -l)

        if [ "$PS_COUNT" -eq 0 ]; then
                echo "No connection - starting ..."
                ssh -N -o ServerAliveInterval=24 -i /root/.ssh/id_dsa_cmkremote -R $PORT_REMOTE:$HOST_LOCAL:$PORT_LOCAL <USER>@<meinHost> &
                if [[ $? -eq 0 ]] && [[ $EXIT != 1 ]]; then
                        EXIT=0
                else
                        EXIT=1
                fi
        else
                echo "There are allready connections ..."
                EXIT=0
        fi
done

exit $EXIT


Tipp: Das Script alle X-Minuten per Cron aufrufen um Verbindungsabbrüche abzufangen ...
Tipp2: Du benötigst hier einen SSH-User, der sich passwortlos anmelden darf ... meiner landet auf einem separatem SSH-Sprungserver in einer Chroot-Umgebung und darf keine Befehle ausführen...


Hier noch die Apache-Konfig

root@webproxy:/etc/apache2/sites-enabled# cat fhem.<meineDomain>.conf
<VirtualHost 172.16.x.x:443>

  ServerName fhem.<meineDomain>
  DocumentRoot /var/www
  ServerAdmin admin@example.com

  SSLEngine on
  SSLCertificateFile /etc/letsencrypt/live/fhem.<meineDomain>/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/fhem.<meineDomain>/privkey.pem

<Location />

    AuthType Basic
    AuthName "Authentication Required"
    AuthUserFile /etc/apache2/fhem.passwd

    require valid-user
   ProxyHTMLEnable On

  # ProxyHTMLURLMap passt Links im HTML/JavaScript Source an
  ProxyHTMLURLMap /        /fhem/
  ProxyHTMLURLMap /fhem/     /fhem/

  SetOutputFilter INFLATE;proxy-html;DEFLATE


</Location>

  ## FHEM-Smartphone
#  ProxyPass /webphone http://172.16.x.x:8084/webphone
#  ProxyPassReverse /webphone http://172.16.x.x:8084/webphone

  ## FHEM-Main
  ProxyPass /  http://172.16.x.x:8083/ retry=0
  ProxyPassReverse / http://172.16.x.x:8083/

  SetEnv force-proxy-request-1.0 1
  SetEnv proxy-nokeepalive 1

  ## Logging, always a good idea.
  LogLevel info
  ErrorLog /var/log/apache2/fhem.<meineDomain>-error_log
  CustomLog /var/log/apache2/fhem.<meineDomain>-request_log combined

</VirtualHost>




Falls du weitere Hilfe benötigst oder dich allgemein über Proxmox austauschen möchtest (auch immer ein schönes Thema :) ) schreib mich per PN an.

Wernieman

Also Quasi ein VPN über ssh .... (Sehr vereinfacht ausgedrückt)
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

erdo_king

Als Informatiker dreht sich mir gerade der Magen um bei dem Vergleich :D
Wenn du es soweit stark vereinfachen möchtest meinetwegen ...

Du baust einen Tunnel auf "RasPi -> Apache", hier also SSH statt VPN und tunnelst deinen Port nach aussen ...
Nur DEUTLICH! sicherer, da man nur einen Port mitnimmt und nicht ein komplettes Netz/Interface!

Zumindest solange man sein SSH anständig absichert.

Wernieman

Btw:
Fürs automatisieren gibt es dann auch "autossh", der automatisch prüft und eine abgebrochene Verbindung wieder aufbaut ...

P.S. ssh als "VPN-Light" ist übrigens nicht auf "meinen Mist gewachsen", sondern stand so sogar schon in der "iX" ...
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

moonsorrox

so ein wenig habe ich gestern und heute weiter gemacht und auf meinem Cubietruck eine Testumgebung mit Fhem und einem Ubuntu 16.04 installiert.

cd /opt
sudo git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto --help

keine Probleme

./letsencrypt-auto certonly --rsa-key-size 4096 -d <domain>

Zertifikat wurde erstellt

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/fhem.resse-hausautomation.de-0001/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/fhem.resse-hausautomation.de-0001/privkey.pem
   Your cert will expire on 2018-01-24. To obtain a new or tweaked
   version of this certificate in the future, simply run
   letsencrypt-auto again. To non-interactively renew *all* of your
   certificates, run "letsencrypt-auto renew"
- If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

alles OK

root@cubieHomeSrv:/opt/letsencrypt# service apache2 restart
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.


dann abgefragt "systemctl status apache2.service"
hier kommt dann das

root@cubieHomeSrv:/opt/letsencrypt# systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Do 2017-10-26 15:08:25 CEST; 26s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 881 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

Okt 26 15:08:25 cubieHomeSrv apache2[881]:  *
Okt 26 15:08:25 cubieHomeSrv apache2[881]:  * The apache2 configtest failed.
Okt 26 15:08:25 cubieHomeSrv apache2[881]: Output of config test was:
Okt 26 15:08:25 cubieHomeSrv apache2[881]: apache2: Syntax error on line 219 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-e
Okt 26 15:08:25 cubieHomeSrv apache2[881]: Action 'configtest' failed.
Okt 26 15:08:25 cubieHomeSrv apache2[881]: The Apache error log may have more information.
Okt 26 15:08:25 cubieHomeSrv systemd[1]: apache2.service: Control process exited, code=exited status=1
Okt 26 15:08:25 cubieHomeSrv systemd[1]: Failed to start LSB: Apache2 web server.
Okt 26 15:08:25 cubieHomeSrv systemd[1]: apache2.service: Unit entered failed state.
Okt 26 15:08:25 cubieHomeSrv systemd[1]: apache2.service: Failed with result 'exit-code'.
lines 1-18/18 (END)


und die Abfrage "journalctl -xe" bringt folgendes:
root@cubieHomeSrv:~# journalctl -xe
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/multiseat
--
-- A new session with the ID c7 has been created for the user root.
--
-- The leading process of the session is 1030.
Okt 26 15:18:06 cubieHomeSrv systemd[1]: Started Session c7 of user root.
-- Subject: Unit session-c7.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-c7.scope has finished starting up.
--
-- The start-up result is done.
Okt 26 15:19:43 cubieHomeSrv systemd[1]: Stopped LSB: Apache2 web server.
-- Subject: Unit apache2.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit apache2.service has finished shutting down.
Okt 26 15:19:43 cubieHomeSrv systemd[1]: Starting LSB: Apache2 web server...
-- Subject: Unit apache2.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit apache2.service has begun starting up.
Okt 26 15:19:43 cubieHomeSrv apache2[1111]:  * Starting Apache httpd web server apache2
Okt 26 15:19:44 cubieHomeSrv apache2[1111]:  *
Okt 26 15:19:44 cubieHomeSrv apache2[1111]:  * The apache2 configtest failed.
Okt 26 15:19:44 cubieHomeSrv apache2[1111]: Output of config test was:
Okt 26 15:19:44 cubieHomeSrv apache2[1111]: apache2: Syntax error on line 219 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/fhem.resse-hausautomation.de.conf: <
Okt 26 15:19:44 cubieHomeSrv apache2[1111]: Action 'configtest' failed.
Okt 26 15:19:44 cubieHomeSrv apache2[1111]: The Apache error log may have more information.
Okt 26 15:19:44 cubieHomeSrv systemd[1]: apache2.service: Control process exited, code=exited status=1
Okt 26 15:19:44 cubieHomeSrv systemd[1]: Failed to start LSB: Apache2 web server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit apache2.service has failed.
--
-- The result is failed.
Okt 26 15:19:44 cubieHomeSrv systemd[1]: apache2.service: Unit entered failed state.
Okt 26 15:19:44 cubieHomeSrv systemd[1]: apache2.service: Failed with result 'exit-code'.
lines 1206-1250/1250 (END)


nun Frage ich mich welche Fehler ich beheben muss, denn auf die https Seite komme ich nicht.

Der Port 443 in der Fritzbox ist auch freigegeben und zeigt auch grün

Intel-NUC i5: FHEM-Server 6.1 :: Perl v5.18.2

Homematic: HM-USB-CFG2,HM-CFG-LAN Adapter, HM-LC-BL1-FM, HM-LC-Sw1PBU-FM, HM-LC-Sw1-PI-2, HM-WDS10-TH-O, HM-CC-TC, HM-LC-SW2-FM

CoolTux

Du hast ein Syntax Fehler in Deiner Apache Config
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

eisi

Zitat
Syntax error on line 1 of /etc/apache2/sites-enabled/fhem.resse-hausautomation.de.conf

Poste mal bitte die ersten Zeilen dieser Datei.
3 x Rasp mit fhem 5.8 | 1 Rasp mit Kodi |1x Cube | 15 x MaxLan Thermostate und 18 Fensterschalter | 30 WLAN Schalter Sonoff | Diverse Sensoren mit Arduino | Tablet mit FTUI 2.6

moonsorrox

Da hatte ich schon geschaut aber es gibt dort keinen Fehler, wenn ich Zuhause bin poste ich die gesamte *.conf mal.
Zumindest ist für mich kein Fehler erkennbar da ich dort nur mein Pfade drin habe...
Intel-NUC i5: FHEM-Server 6.1 :: Perl v5.18.2

Homematic: HM-USB-CFG2,HM-CFG-LAN Adapter, HM-LC-BL1-FM, HM-LC-Sw1PBU-FM, HM-LC-Sw1-PI-2, HM-WDS10-TH-O, HM-CC-TC, HM-LC-SW2-FM

Wernieman

Und was hat die Datei für Berechtigungen?
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

moonsorrox

#11
Berechtigung ist 755
das ist die conf:
Zitat<IfModule mod_ssl.c> <VirtualHost *:443>
    ServerName fhem.resse-hausautomation.de
    ServerAdmin fhem@resse-hausautomation.de
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/fhem.resse-hausautomation.de.error.log
    CustomLog ${APACHE_LOG_DIR}/fhem.resse-hausautomation.de.access.log combined
    SSLCertificateFile /etc/letsencrypt/live/fhem.resse-hausautomation.de/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/fhem.resse-hausautomation.de/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On
    <Location /fhem>
        ProxyPass http://localhost:8083/fhem
        ProxyPassReverse http://localhost:8083/fhem
    </Location>
    <Directory />
        RedirectPermanent / /fhem
    </Directory>
    <Proxy *>
        AuthType Basic
        AuthName "Password for FHEM Required"
        AuthUserFile /etc/fhem-htpasswd
        Require valid-user
        Order deny,allow
        Allow from all
    </Proxy> </VirtualHost>
</IfModule>

wenn ich jetzt nochmal den Apache starte zeigt er mir:
root@cubieHomeSrv:~# service apache2 restart
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.


Dann gebe ich folgendes ein: systemctl status apache2.service
root@cubieHomeSrv:~# systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Do 2017-10-26 23:34:17 CEST; 23s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 6277 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

Okt 26 23:34:17 cubieHomeSrv apache2[6277]:  *
Okt 26 23:34:17 cubieHomeSrv apache2[6277]:  * The apache2 configtest failed.
Okt 26 23:34:17 cubieHomeSrv apache2[6277]: Output of config test was:
Okt 26 23:34:17 cubieHomeSrv apache2[6277]: apache2: Syntax error on line 219 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/fhem.resse-hausautomation.de.conf<IfModule takes one argument, Containe
Okt 26 23:34:17 cubieHomeSrv apache2[6277]: Action 'configtest' failed.
Okt 26 23:34:17 cubieHomeSrv apache2[6277]: The Apache error log may have more information.
Okt 26 23:34:17 cubieHomeSrv systemd[1]: apache2.service: Control process exited, code=exited status=1
Okt 26 23:34:17 cubieHomeSrv systemd[1]: Failed to start LSB: Apache2 web server.
Okt 26 23:34:17 cubieHomeSrv systemd[1]: apache2.service: Unit entered failed state.
Okt 26 23:34:17 cubieHomeSrv systemd[1]: apache2.service: Failed with result 'exit-code'.
lines 1-18/18 (END)
Intel-NUC i5: FHEM-Server 6.1 :: Perl v5.18.2

Homematic: HM-USB-CFG2,HM-CFG-LAN Adapter, HM-LC-BL1-FM, HM-LC-Sw1PBU-FM, HM-LC-Sw1-PI-2, HM-WDS10-TH-O, HM-CC-TC, HM-LC-SW2-FM

amenomade

Mit welchem Editor arbeitest Du, bzw. ist die Datei mit UTF8 kodiert?
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

moonsorrox

Ich arbeite mit Notepad++ oder auch mal mit Brackets.
Intel-NUC i5: FHEM-Server 6.1 :: Perl v5.18.2

Homematic: HM-USB-CFG2,HM-CFG-LAN Adapter, HM-LC-BL1-FM, HM-LC-Sw1PBU-FM, HM-LC-Sw1-PI-2, HM-WDS10-TH-O, HM-CC-TC, HM-LC-SW2-FM

CoolTux

Startet denn der Indianer wenn Du Deine Config mal aus der sites-enabled raus nimmst?
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net