nginx und php

Begonnen von dt2510, 06 Juni 2018, 13:33:55

Vorheriges Thema - Nächstes Thema

dt2510

Ich habe gerade ein Reverse Proxy für meine FHEM Installation unter Ubuntu eingerichtet und möchte nun in meinem TabletUI Frontend php verwenden.

Wie installiere ich php (vermutlich mit sudo apt-get install php5-fpm) und wie konfiguriere ich mein Reverse Proxy so, damit ich php verwenden kann ?

Wernieman

#1
Sorry aber für php mit nginx (und ja, dafür braucht du php-fpm) möchte ich Dich definitiv auf google Verweisen. Dafür gibt es wirklich genügend Anleitungen ...

Mal ein schneller Fund:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
Dort ab Step 3...
- 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

dt2510

ich versuche mal mein Glück ... ich vermute mal, daß die Konfiguration dann in die Datei reverse-proxy und nicht in default eingetragen wird.

Wernieman

Du solltest unter sides-enabled eine Datei pro Domain machen (es sei denn, Du hast einen VHost, der auf mehrere Domains "lauscht"

Edit:
Bevor Du weiter bastelst: Stichwort Backup
- 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

dt2510

#4
Ich hab' jetzt php Installiert und in meinem Reverse Proxy folgende Einträge hinzugefügt (fett - edit: funktionert nicht innerhalb von code ;) ):

  server {
      listen 80;
      return 301 https://$host$request_uri;
  }
  server {
      listen 443;
[b]      index index.php index.html; [/b]
      server_name NUC6CAYH;
      ssl_certificate           /etc/nginx/cert.crt;
      ssl_certificate_key       /etc/nginx/cert.key;
      ssl on;
      ssl_session_cache  builtin:1000  shared:SSL:10m;
      ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
      ssl_prefer_server_ciphers on;
      access_log            /var/log/nginx/jenkins.access.log;
      location / {
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_http_version      1.1;
        proxy_pass              http://localhost:8085;
        proxy_read_timeout  90;
        set $my_http_upgrade "";
        set $my_connection "Connection";
        proxy_set_header Upgrade $my_http_upgrade;
        proxy_set_header Connection $my_connection;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_redirect          http://localhost:8088 https://localhost;
      }
[b]      location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }[/b]
  }   


Auf die FHEM Konsole (FHEMWEB) komme ich problemlos. Zum Test habe ich eine Datei phpinfo.php im Ordner tabletui angelegt

<?php
phpinfo
();
?>


Möchte ich die Datei im Browser öffnen (https://192.168.220.242/fhem/tabletui/phpinfo.php) bekomme ich eine 404 Meldung von nginx.
Gebe ich eine nicht existierende Datei an, bekomme ich z.B.

File not found: ./www/tablet/tabletui/phpinfo.html

https://192.168.220.242/fhem/tabletui/index.html für TABLETUI funktioniert einwandfrei.

Was hab' ich in der Konfiguration falsch gemacht ?

Wernieman

keine "root" Direktive. Das hast Du als Proxy bisher nicht gebraucht ....
- 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

dt2510

ich habe den Pfad zu meinem TabletUI (dort liegt die phpinfo.php) als root vor der Zeile index ... angegeben

root /opt/fhem/www/tablet/tabletui;

Macht aber keinen Unterschied. Die Oberfläche kann ich weiterhin problemlos aufrufen.


dt2510

Kann das überhaupt funktionieren ?

nginx leitet ja praktisch nur die Anfrage weiter an den FHEM Webserver. Kann dann überhaupt zusätzlich php genutzt werden oder müsste der FHEM Webserver das nicht übernehmen ?

Wernieman

Reihenfolge der Location Ändern, d.h. php vor /

Bei mir funzt es, da ich nicht / sondern /fhem weiterleite ...
- 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

dt2510

Ich hab' jetzt die Reihenfolge geändert, aber das hilft leider auch nicht. Wie sieht denn Deine reverse-proxy Definition aus ?