Apache/Apache+HTTP2+PHP-FPM+TLS1.3: Unterschied zwischen den Versionen

aus www.kruedewagen.de, Homepage von Ralf und Judith Krüdewagen (Kruedewagen)
Zur Navigation springen Zur Suche springen
(14 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 3: Zeile 3:
==Info zu HTTP/2==
==Info zu HTTP/2==
*https://en.wikipedia.org/wiki/HTTP%2F2
*https://en.wikipedia.org/wiki/HTTP%2F2
*HTTP/2 mit Nginx mit Erläuterungen zu Request-Analyse mit Browser-Tools: siehe LM 02/21 S.36


==PHP-FPM==
==PHP-FPM==
Zeile 8: Zeile 9:


===Info===
===Info===
*https://wiki.apache.org/httpd/PHP-FPM
*[https://wiki.apache.org/httpd/PHP-FPM PHP-FPM Apache]
*[https://en.opensuse.org/SDB:Apache_FastCGI_and_PHP-FPM_configuration Apache FastCGI and PHP-FPM configuration] (SUSE)
*[https://cwiki.apache.org/confluence/display/HTTPD/PHP-FPM PHP-FPM] (cwiki.apache.org)
*[https://localhorst.org/http-2-0-debian-9-apache-2-4-umstellung-auf-php-fpm/ HTTP/2.0 Debian 9 Apache 2.4 Umstellung auf php-fpm]
*[https://www.digitalocean.com/community/tutorials/how-to-configure-apache-http-with-mpm-event-and-php-fpm-on-ubuntu-18-04-de So konfigurieren Sie Apache HTTP mit MPM Event und PHP-FPM unter Ubuntu 18.04]


===Konfiguration===
===Konfiguration===
Zeile 25: Zeile 30:
listen.group = www
listen.group = www
listen.mode = 0660
listen.mode = 0660
</syntaxhighlight>
Tuning der Parameter [https://docs.nextcloud.com/server/21/admin_manual/installation/server_tuning.html]:
<syntaxhighlight lang="php">
pm = dynamic
pm.max_children = 120
pm.start_servers = 12
pm.min_spare_servers = 6
pm.max_spare_servers = 18
</syntaxhighlight>
</syntaxhighlight>


Zeile 64: Zeile 78:
*Lösung: AppArmor Profile deaktivieren:
*Lösung: AppArmor Profile deaktivieren:
  aa-disable php-fpm
  aa-disable php-fpm
*Als Ersatz für AppArmor ''open_basedir'' in php.ini setzen
*Links
*Links
**https://www.digitalocean.com/community/tutorials/how-to-create-an-apparmor-profile-for-nginx-on-ubuntu-14-04
**https://www.digitalocean.com/community/tutorials/how-to-create-an-apparmor-profile-for-nginx-on-ubuntu-14-04
Zeile 76: Zeile 91:
*[https://icing.github.io/mod_h2/howto.html how to h2 in apache]
*[https://icing.github.io/mod_h2/howto.html how to h2 in apache]
*[https://http2.pro/doc/Apache How to enable HTTP/2 support in Apache]
*[https://http2.pro/doc/Apache How to enable HTTP/2 support in Apache]
*[https://blog.wappler.systems/opensuse-leap-15-apache-2-php-fpm-http2/ OpenSuse Leap 15: Apache 2, PHP FPM, HTTP2, ImageMagick]


===MPM===
===MPM===
Zeile 91: Zeile 107:
Modul aktivieren in Datei ''/etc/sysconfig/apache2'' ("php7" entfernen):
Modul aktivieren in Datei ''/etc/sysconfig/apache2'' ("php7" entfernen):
  APACHE_SERVER_FLAGS="... proxy proxy_http proxy_fcgi"
  APACHE_SERVER_FLAGS="... proxy proxy_http proxy_fcgi"
Modul konfigurieren in Datei ''/etc/apache2/conf.d/mod_fcgid.conf'' (oder an anderer Stelle):
<syntaxhighlight lang="apache">
<IfModule proxy_fcgi_module>
DirectoryIndex index.php
<FilesMatch "\.ph(p[345]?|tml)$">
    #SetHandler "proxy:fcgi://127.0.0.1:9000"
    SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
<FilesMatch "\.php[345]?s$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>
</syntaxhighlight>
:Achtung: ''mod_fcgid.conf'' unter openSUSE war fehlerhaft!


Apache neu starten:
Apache neu starten:
  systemctl restart apache2
  systemctl restart apache2
Prüfen ob Module und Konfig-Dateien geladen wurden
apachectl -t -D DUMP_MODULES
apachectl -t -D DUMP_INCLUDES


===HTTP/2===
===HTTP/2===
HTTP2 (h2) einrichten.
HTTP/2 grundsätzlich aktivieren in Datei ''/etc/sysconfig/apache2'':
HTTP/2 grundsätzlich aktivieren in Datei ''/etc/sysconfig/apache2'':
  APACHE_SERVER_FLAGS="... HTTP2"
  APACHE_SERVER_FLAGS="... HTTP2"
Zeile 105: Zeile 140:


HTTP/2 Protokoll aktivieren in Datei ''/etc/apache2/protocols.conf'':
HTTP/2 Protokoll aktivieren in Datei ''/etc/apache2/protocols.conf'':
<syntaxhighlight lang="apache">
  <IfDefine HTTP2>
  <IfDefine HTTP2>
   <IfModule mod_http2.c>
   <IfModule mod_http2.c>
Zeile 110: Zeile 146:
   </IfModule>
   </IfModule>
  </IfDefine>
  </IfDefine>
</syntaxhighlight>
:Achtung: Die Datei ''protocols.conf'' muss durch ''httpd.conf'' geladen werden.
   
   
Apache neu starten:
Apache neu starten:
  systemctl restart apache2
  systemctl restart apache2
Prüfen ob Module und Konfig-Dateien geladen wurden
apachectl -t -D DUMP_MODULES
apachectl -t -D DUMP_INCLUDES


===TLS 1.3===
===TLS 1.3===
TLS 1.3 kann pro Virtual Host konfiguriert werden:
<syntaxhighlight lang="apache">
...
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4"
...
</syntaxhighlight>
===Endprüfung===
HTTP/2 und TLS prüfen:
curl -s -v --http2 https://www.kruedewagen.de/


Ausgabe sollte enthalten:
<pre>
* ALPN, offering h2
* ALPN, offering http/1.1
...
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
...
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5559c77602a0)
...
</pre>


Alternativen:
*Es kann einen Browsererweiterung wie "HTTP/2 Indicator" für Firefox installiert werden, die in der Adresszeile angibt, ob HTTP/2 verwendet wird.
*Im Entwicklerwerkzeug des Browsers die Antwort inspizieren, z.B.
X-Firefox-Spdy h2


[[Kategorie:Webserver]]
[[Kategorie:Webserver]]

Version vom 19. April 2021, 09:37 Uhr

Diese Seite beschreibt, wie man Apache so einrichtet, dass es HTTP/2 beherrscht. Dabei wird gleich auch TLS 1.3 und für PHP-Anwendungen PHP-FPM eingerichtet. Die Beispiele sind unter openSUSE entstanden.

Info zu HTTP/2

PHP-FPM

PHP-FPM wird benötigt, da Apache für HTTP/2 nicht im Prefork-Modus laufen kann, sondern ein anderes Multi-Processing-Modul wie "event" verwendet werden muss (siehe unten). Das Standard-PHP-Modul für Apache funktioniert jedoch nicht mehr mit "event", so dass für PHP-Anwendungen eine andere Lösung implementiert werden muss. PHP-FPM läuft als eigenständiger Dienst und kann sowohl per TCP als auch per Unix Socket angesprochen werden.

Info

Konfiguration

Datei /etc/php7/fpm/php-fpm.conf: Default-Datei kann verwendet werden.

Datei /etc/php7/fpm/php-fpm.d/www.conf (Erste Variante für TCP, zweite für Unix Socket - geht aber nicht parallel):

user = wwwrun
group = www
listen = 127.0.0.1:9000
listen = /run/php-fpm/php-fpm.sock
listen.owner = wwwrun
listen.group = www
listen.mode = 0660

Tuning der Parameter [1]:

pm = dynamic
pm.max_children = 120
pm.start_servers = 12
pm.min_spare_servers = 6
pm.max_spare_servers = 18

Datei /etc/php7/fpm/php.ini:

  • Hier sollte manuell eine Kopie der für Apache gültigen Ini-Datei abgelegt werden.
cp -p /etc/php7/apache2/php.ini /etc/php7/fpm/
  • Achtung: Ohne diese Datei fehlen viele Konfigurationseinstellungen!!

Dienst einrichten und starten

systemctl enable php-fpm
systemctl start php-fpm

Prüfen

  • Prozesse laufen als wwwrun:
ps -ef|grep php-fpm
wwwrun    7295 22565  1 07:43 ?        00:00:08 php-fpm: pool www
wwwrun    9294 22565  2 07:51 ?        00:00:00 php-fpm: pool www
wwwrun    9406 22565  1 07:51 ?        00:00:00 php-fpm: pool www
root     22565     1  0 Nov10 ?        00:00:05 php-fpm: master process (/etc/php7/fpm/php-fpm.conf)
  • Datei für Unix Socket (Rechte):
ls -la /run/php-fpm/php-fpm.sock
srw-rw---- 1 wwwrun www 0 10. Nov 15:47 /run/php-fpm/php-fpm.sock
  • Für TCP:
netstat -an|grep 9000
  • Prüfen per phpinfo():
Configuration File (php.ini) Path 	/etc/php7/fpm
Loaded Configuration File 	/etc/php7/fpm/php.ini
Scan this dir for additional .ini files 	/etc/php7/conf.d 

Fallstricke

AppArmor

  • Unter openSUSE läuft AppArmor. Die Default-Konfiguration /etc/apparmor.d/php-fpm schränkt PHP-FPM aber zu sehr ein. Es gibt im Browser einen Fehler "Access denied" bei PHP-Anwendungen.
  • AppArmor zum Testen temporär deaktivieren:
aa-teardown
aa-status
  • Lösung: AppArmor Profile deaktivieren:
aa-disable php-fpm

Apache

Info

MPM

Als MPM kann für HTTP/2 nicht "prefork" verwendet werden, sondern am besten "event".

MPM aktivieren in Datei /etc/sysconfig/apache2:

APACHE_MPM="event"

PHP Modul

Das Standard-Modul "php7" kann nicht mehr verwendet werden, stattdessen wird "proxy_fcgi" verwendet.

Modul installieren:

zypper in apache2-mod_fcgid

Modul aktivieren in Datei /etc/sysconfig/apache2 ("php7" entfernen):

APACHE_SERVER_FLAGS="... proxy proxy_http proxy_fcgi"

Modul konfigurieren in Datei /etc/apache2/conf.d/mod_fcgid.conf (oder an anderer Stelle):

<IfModule proxy_fcgi_module>

DirectoryIndex index.php
<FilesMatch "\.ph(p[345]?|tml)$">
    #SetHandler "proxy:fcgi://127.0.0.1:9000"
    SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
<FilesMatch "\.php[345]?s$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

</IfModule>
Achtung: mod_fcgid.conf unter openSUSE war fehlerhaft!

Apache neu starten:

systemctl restart apache2

Prüfen ob Module und Konfig-Dateien geladen wurden

apachectl -t -D DUMP_MODULES
apachectl -t -D DUMP_INCLUDES

HTTP/2

HTTP/2 grundsätzlich aktivieren in Datei /etc/sysconfig/apache2:

APACHE_SERVER_FLAGS="... HTTP2"

HTTP/2 Modul aktivieren in Datei /etc/sysconfig/apache2:

APACHE_SERVER_FLAGS="... proxy proxy_http proxy_fcgi http2"

HTTP/2 Protokoll aktivieren in Datei /etc/apache2/protocols.conf:

 <IfDefine HTTP2>
  <IfModule mod_http2.c>
    Protocols h2 h2c http/1.1
  </IfModule>
 </IfDefine>
Achtung: Die Datei protocols.conf muss durch httpd.conf geladen werden.

Apache neu starten:

systemctl restart apache2

Prüfen ob Module und Konfig-Dateien geladen wurden

apachectl -t -D DUMP_MODULES
apachectl -t -D DUMP_INCLUDES

TLS 1.3

TLS 1.3 kann pro Virtual Host konfiguriert werden:

...
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4"
...

Endprüfung

HTTP/2 und TLS prüfen:

curl -s -v --http2 https://www.kruedewagen.de/

Ausgabe sollte enthalten:

* ALPN, offering h2
* ALPN, offering http/1.1
...
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
...
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5559c77602a0)
...

Alternativen:

  • Es kann einen Browsererweiterung wie "HTTP/2 Indicator" für Firefox installiert werden, die in der Adresszeile angibt, ob HTTP/2 verwendet wird.
  • Im Entwicklerwerkzeug des Browsers die Antwort inspizieren, z.B.
X-Firefox-Spdy	h2