Commit e51d54

2023-09-30 13:10:00 Ralph Thesen: added example for multiple vhosts.
howto/nginx-public_html.md ..
@@ 6,7 6,146 @@
<mark>Please consider all files in the exported folders as public, since any k8s pod can mount it via nfs. name the directories accordingly, e.g. `public_html` or `share`.</mark>
-## k8s deployment, service and ingress
+## One nginx for multiple domains: k8s deployment, services and ingress
+
+An example for an nginx deployment with multiple virtualhosts can be found below. Make sure to replace all the
+
+- domain1.tld
+- doman2.tld
+- username
+
+```yaml
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: nginx-conf
+ namespace: username-vserver
+data:
+ virtualhost.conf: |
+ server {
+ listen 80;
+ server_name domain1.tld www.domain1.tld;
+ root /var/www/html/domain1.tld;
+ index index.html;
+ location / {
+ try_files $uri $uri/ =404;
+ }
+ }
+
+ server {
+ listen 80;
+ server_name domain2.tld www.domain2.tld;
+ root /var/www/html/domain2.tld;
+ index index.html;
+ location / {
+ try_files $uri $uri/ =404;
+ }
+ }
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: nginx-static
+ namespace: username-vserver
+spec:
+ selector:
+ matchLabels:
+ app: nginx-static
+ replicas: 1
+ template:
+ metadata:
+ labels:
+ app: nginx-static
+ spec:
+ containers:
+ - name: nginx
+ image: nginx:1.14.2
+ command:
+ - /bin/sh
+ - -c
+ - |
+ sed -i '/^nginx/d' /etc/passwd
+ sed -i '/^nginx/d' /etc/group
+ echo "nginx:x:101:101:nginx user,,,:/nonexistent:/bin/false" >> /etc/passwd
+ echo "nginx:x:101:" >> /etc/group
+ nginx -g 'daemon off;'
+ ports:
+ - containerPort: 80
+ volumeMounts:
+ - name: nginx-conf
+ subPath: virtualhost.conf
+ mountPath: /etc/nginx/conf.d/virtualhost.conf
+ - name: nfs-public-html
+ mountPath: /var/www/html
+ volumes:
+ - name: nginx-conf
+ configMap:
+ name: nginx-conf
+ items:
+ - key: virtualhost.conf
+ path: virtualhost.conf
+ - name: nfs-public-html
+ nfs:
+ server: 10.1.0.2
+ path: /home/username/public_html
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: nginx-static
+ namespace: username-vserver
+spec:
+ ports:
+ - port: 80
+ targetPort: 80
+ protocol: TCP
+ selector:
+ app: nginx-static
+---
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ name: nginx-static
+ namespace: username-vserver
+ annotations:
+ cert-manager.io/cluster-issuer: "letsencrypt-production"
+ nginx.ingress.kubernetes.io/ssl-redirect: "true"
+ nginx.ingress.kubernetes.io/server-alias: "www.domain1.tld,www.domain2.tld,domain2.tld"
+spec:
+ ingressClassName: "nginx"
+ tls:
+ - hosts:
+ - domain1.tld
+ - www.domain1.tld
+ - domain2.tld
+ - www.domain2.tld
+ secretName: nginx-static-tls
+ rules:
+ - host: domain1.tld
+ http:
+ paths:
+ - path: /
+ pathType: Prefix
+ backend:
+ service:
+ name: nginx-static
+ port:
+ number: 80
+ - host: domain2.tld
+ http:
+ paths:
+ - path: /
+ pathType: Prefix
+ backend:
+ service:
+ name: nginx-static
+ port:
+ number: 80
+
+```
+
+## One nginx per domain: k8s deployment, service and ingress
An example for an nginx deployment can be found below. Make sure to replace all the
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9