我在一个Kubernetes pod中同时使用nginx和IIS服务器时遇到了一个奇怪的问题。这似乎是nginx. conf的问题。如果我绕过nginx直接进入IIS,我会看到标准登录页面-x1c 0d1x
但是,当我尝试通过反向代理时,我看到了以下部分结果-
以下是这些文件:
nginx.conf:
events {
worker_connections 4096; ## Default: 1024
}
http{
server {
listen 81;
#Using variable to prevent nginx from checking hostname at startup, which leads to a container failure / restart loop, due to nginx starting faster than IIS server.
set $target "http://127.0.0.1:80/";
location / {
proxy_pass $target;
}
}
}
deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
...
name: ...
spec:
replicas: 1
selector:
matchLabels:
pod: ...
template:
metadata:
labels:
pod: ...
name: ...
spec:
containers:
- image: claudiubelu/nginx:1.15-1-windows-amd64-1809
name: nginx-reverse-proxy
volumeMounts:
- mountPath: "C:/usr/share/nginx/conf"
name: nginx-conf
imagePullPolicy: Always
- image: some-repo/proprietary-server-including-iis
name: ...
imagePullPolicy: Always
nodeSelector:
kubernetes.io/os: windows
imagePullSecrets:
- name: secret1
volumes:
- name: nginx-conf
persistentVolumeClaim:
claimName: pvc-nginx
从一个卷Mapnginx.conf文件只是快速测试不同配置的一种方便方法,新配置可以使用kubectl cp ./nginx/conf nginx-busybox-pod:/mnt/nginx/
交换进来。
Busybox盒(用于访问PVC):
apiVersion: v1
kind: Pod
metadata:
name: nginx-busybox-pod
namespace: default
spec:
containers:
- image: busybox
command:
- sleep
- "360000"
imagePullPolicy: Always
name: busybox
volumeMounts:
- name: nginx-conf
mountPath: "/mnt/nginx/conf"
restartPolicy: Always
volumes:
- name: nginx-conf
persistentVolumeClaim:
claimName: pvc-nginx
nodeSelector:
kubernetes.io/os: linux
最后是PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nginx
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Mi
storageClassName: azurefile
知道为什么吗?
1条答案
按热度按时间ybzsozfc1#
经过一些测试,下面是一个可以工作的nginx.conf -
proxy_set_header Host $host;
target
变量中删除尾部斜杠。$host:$server_port
代替$host
可以更好地访问服务器上的其他端点。这是由于应用服务器将传入请求重定向到不同的URI,在此过程中丢失了代理的端口(81)。