I’m installing a Ghost blog by using the stack Nginx + Kubernetes with Ingress Nginx. My K8s deployment and Nginx config are as below.
The problem is that when accessing the deployed blog, I got the too many redirects error from the browser. And I guess that the root cause is the HTTPS URL is not configured properly in the Nginx ingress but I haven’t got the right way to resolve it. Someone can point me to what’s wrong here?
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-blog
spec:
rules:
- host: my-blog.com
http:
paths:
- backend:
service:
name: my-blog
port:
number: 2368
path: /
pathType: Prefix
---
apiVersion: v1
kind: Service
metadata:
labels:
app: my-blog
name: my-blog
spec:
ports:
- port: 2368
protocol: TCP
selector:
app: my-blog
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: my-blog
name: my-blog
spec:
replicas: 1
selector:
matchLabels:
app: my-blog
template:
metadata:
labels:
app: my-blog
spec:
containers:
- env:
- name: url
value: https://my-blog.com
image: ghost:latest
name: my-blog
ports:
- containerPort: 2368
terminationGracePeriodSeconds: 30
server {
server_name my-blog.com;
location / {
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 https;
proxy_set_header Host $http_host;
proxy_intercept_errors on;
proxy_pass http://k8s_cluster;
}
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/my-blog.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/my-blog.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = my-blog.com) {
return 301 https://$host$request_uri;
}
server_name my-blog.com;
listen 80;
return 404;
}