Skip to content

Instantly share code, notes, and snippets.

@g4s
Last active March 5, 2021 12:26
Show Gist options
  • Save g4s/74c4ecf4a25322fd141a4dcfe6f31770 to your computer and use it in GitHub Desktop.
Save g4s/74c4ecf4a25322fd141a4dcfe6f31770 to your computer and use it in GitHub Desktop.
nginx mit PHP auf example.com und als Reverse Proxy für Matrix auf matrix.example.com
# nginx Konfiguration für eine PHP Anwendung unter example.com, sowie als
# Reverse Proxy für einen matrix server unter matrix.example.com
#
# vgl hierzu auch die nginx Dokumentation, sowie ein Konfigurationsbeispiel
# unter: https://www.nginx.com/resources/wiki/start/topics/examples/full/
server {
# Konfiguration des Reverse Proxys für matrix mit der subdomain "matrix.example.com"
listen 80; # lausche auf Port 80 (HTTP) / IPv4
listen [::]:80; # lausche auf Port 80 (HTTP) / IPv6
server_name matrix.example.com; # zu ersetzen durch den passenden DNS Eintrag
return 301 https://$host$request_uri; # leite automatisch mit HTTP Code 301 auf die SSL geschützte Seite um
}
server {
# Konfiguration des Reverse Proxys für matrix mit der subdomain "matrix.example.com"
listen 443 ssl; # lausche auf Port 443 (HTTPS) / IPv4 und erwarte SSL encrypted Traffic
listen [::]:443 ssl; # lausche auf Port 443 (HTTPS) / IPv6 und erwarte SSL encrypted Traffic
server_name matrix.example.com; # zu ersetzen durch den passenden DNS Eintrag
ssl on;
ssl_certificate /etc/letsencrypt/live/matrix.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/matrix.example.com/privkey.pem;
location / {
# hier erfolgt die interne Umleitung auf den eigentlich matrix Application Server
# welcher auf localhost, Port 8008 lauscht (kommt auf die matrix Konfiguration an)
# es wird alles ab matrix.example.com/ weitergeleitet.
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
server {
# im Grunde genau das Gleiche wie in den Zeilen 11-28
listen 8448 ssl default_server;
listen [::]:8448 ssl default_server;
server_name matrix.example.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/matrix.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/matrix.example.com/privkey.pem;
location / {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
# Einfügen der Webseite example.com
server {
listen 80;
listen [::]:80;
server_name example.com
return 301 https://$host$request_uri;
}
server {
listen 443;
listen [::]:443;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root html;
# für PHP Anwendungen / Webseiten (php/fastCGI)
#
# Erklärung: hier wird nginx angewiesen,PHP Dateien auszuführen, sofern diese
# im WebRoot gefunden. Hierzu wird jede PHP Datei an FastCGI weitergereicht
# (läuft im Default auf Port 1025, auf dem selben Host). FastCGI evaluiert dann
# das PHP und schickt an nginx das Ergebnis zurück.
#
# Dies ist nötig, da nginx nicht von Hause aus PHP ausfähren kann.
location \.php$ {
fastcgi_pass localhost:1025;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment