Port Forwarding to LXCs to run Apache Webserver (Lamp Stack)

Wolkegerm

New Member
Sep 5, 2024
15
1
3
Habe ein laufendes LXC Setup, wo jeder Container 8.8.8.8 anpingen kann.
Nun wollte ich auf einem LXC einen Lamp Server installieren, um meine Homepage zum Laufen zu bekommen.
Hatte schon etliche solcher Installationen, aber ohne Proxmox Zwischenschicht.
So weit läuft alles, aber ich kann den Lamp Stack nicht über die Public Ip erreichen.
Kann sich jemand mal die Config anschauen?


VPS Network Config /etc/network/interfaces

Code:
auto lo
iface lo inet loopback

iface ens3 inet manual

auto vmbr0
iface vmbr0 inet static
        address  x.x.x.x/22
        gateway x.x.x.x
        netmask  255.255.255.0
        bridge-ports ens3
        bridge-stp off
        bridge-fd 0

auto vmbr1
#private sub network
iface vmbr1 inet static
        address  10.10.10.1/24
        netmask  255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0

        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up iptables -t nat -A POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE
        post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -o vmbr0 -j MASQUERADE
        
        post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
        post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1

LXC Container:

IPv4: Static
IPv4/CIDR: 10.10.10.2/24
Gateway (IPv4): 10.10.10.1

----------------------------------------------------------------------------------

Setup @ LCX Container beinhaltet:
- Apache
- MySQL Server
- PHP Server mit PhP My Admin

Nach service apache2 restart wollte ich auf http://x.x.x.x:80 bzw. http://x.x.x.x:443 die php info Page aufsuchen. Bekomme aber keine Verbindung.
Ich habe den Verdacht, dass ich das PREROUTING verändern muss. Bin mir nicht ganz sicher, ob raw richtig ist und wie ich die Ports weiterleite / freigebe,

Wer hat da Ahnung?
 
Du hast NAT für outgoing Traffic aktiviert (SNAT), jetzt müsstest du noch DNAT einrichten, damit der Container von außen erreichbar ist:

Code:
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 10.10.10.2:80
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 10.10.10.2:443
 
  • Like
Reactions: Wolkegerm
Du hast NAT für outgoing Traffic aktiviert (SNAT), jetzt müsstest du noch DNAT einrichten, damit der Container von außen erreichbar ist:

Code:
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 10.10.10.2:80
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 10.10.10.2:443
Kann ich das nicht gleich bündeln, wenn ich noch andere Ports freigeben möchte?
Das würde dann doch so aussehen oder? @shanreich


post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp -m multiport --dports 1:21,23:8005,8008:65535 -j DNAT --to 10.10.10.2
post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp -m multiport --dports 1:21,23:8005,8008:65535 -j DNAT --to 10.10.10.2

post-up iptables -t nat -A PREROUTING -i vmbr0 -p udp -m multiport --dports 1:21,23:8005,8008:65535 -j DNAT --to 10.10.10.2
post-down iptables -t nat -D PREROUTING -i vmbr0 -p udp -m multiport --dports 1:21,23:8005,8008:65535 -j DNAT --to 10.10.10.2
 
bin mir nicht 100%ig sicher ob das bei DNAT so funktioniert, denke aber schon. Wahrscheinlich ist ausprobieren am einfachsten / schnellsten.
 
  • Like
Reactions: Wolkegerm
bin mir nicht 100%ig sicher ob das bei DNAT so funktioniert, denke aber schon. Wahrscheinlich ist ausprobieren am einfachsten / schnellsten.
Danke.
Du hast NAT für outgoing Traffic aktiviert (SNAT), jetzt müsstest du noch DNAT einrichten, damit der Container von außen erreichbar ist:

Code:
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 10.10.10.2:80
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 443 -j DNAT --to 10.10.10.2:443

Wie kann ich das erweitern, wenn ich weitere LXCs haben möchte?
z.B. 10.10.10.3 / 10.10.10.4 usw.
Ich hab das so gemacht:
2024-09-16 22_20_49-picommathree - Proxmox Virtual Environment – Mozilla Firefox.png
Sieht komisch aus, scheint aber zu funktionieren. Das wird aber irgendwann lang, wenn ich mehrere LXCs habe..

Möchte gerade ein Setup aufbauen, wo folgende Container drin sind:

LXC 1: nginx reverse proxy / Der soll auf 10.10.10.99 laufen.
LXC 2: Application Tier / 10.10.10.100
LXC 3: Datenbank Server für die Applikation auf LCX 2 z.B. auf 10.10.10.101
##########################################################################################

Auf dem LCX 2 sieht es wie folgt aus:
2024-09-16 22_27_08-picommathree - Proxmox Virtual Environment – Mozilla Firefox.png
Da läuft eine Applikation (Matrix Chat Server) auf 10.10.10.100 als localhost mit dem Port 8008.

Nun hab ich mal auf dem LXC 3 den LXC 2 angepingt.
2024-09-16 22_30_19-picommathree - Proxmox Virtual Environment – Mozilla Firefox.png

Scheint so, als ob der Port benutzbar ist.

Ab hier verschleife ich das Ticket:

Auf LCX 2 läuft Matrix Synapse:

https://www.howtoforge.de/anleitung/so-installierst-du-matrix-synapse-chat-unter-ubuntu-22-04/
Die Installation habe ich durchgemacht und alles lief gut.

Nun möchte ich aber den Reverse Proxy in der Install Routine trennen, damit der auf einem andere LXC läuft.


server {
listen 80;
server_name matrix.meinedomain.de;
location / {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
}

Ich hab das Gefühl, dass folgende Zeilen dann nicht richtig sind. Hab das schon mehrfach versucht.

proxy_pass http://localhost:8008 Müsste da nicht http://10.10.10.100:8008 rein?
proxy_set_header X-Forwarded-For $remote_addr;
 

Attachments

  • 2024-09-16 22_27_08-picommathree - Proxmox Virtual Environment – Mozilla Firefox.png
    2024-09-16 22_27_08-picommathree - Proxmox Virtual Environment – Mozilla Firefox.png
    8.7 KB · Views: 0
  • 2024-09-16 22_30_19-picommathree - Proxmox Virtual Environment – Mozilla Firefox.png
    2024-09-16 22_30_19-picommathree - Proxmox Virtual Environment – Mozilla Firefox.png
    5.7 KB · Views: 1
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!