问题描述

使用k8s部署nginx,配置文件使用configmap:

apiVersion: v1
kind: ConfigMap
metadata:
    name: nginx-config
data:
  default.conf: |
    server {
      listen       80;
      server_name  localhost;

      location / {
          proxy_set_header   X-Forwarded-Proto $scheme;
          proxy_set_header   Host              $http_host;
          proxy_set_header   X-Real-IP         $remote_addr;
          proxy_pass http://127.0.0.1:3000;
      }
    }

报错如下:

nginx: [emerg] invalid number of arguments in "proxy_set_header" directive in /etc/nginx/conf.d/default.conf:

解决

配置文件放到configmap中,$变量需要转义:
在这里插入图片描述
修改后如下:

apiVersion: v1
kind: ConfigMap
metadata:
    namespace: txwl-ops
    name: grafana-nginx-config
data:
  default.conf: |
    server {
      listen       80;
      server_name  localhost;
      location /ops-server {
          proxy_pass http://txwl-ops-server-svc:8080/;
      }

      location / {
          proxy_set_header   X-Forwarded-Proto \$scheme;
          proxy_set_header   Host              \$http_host;
          proxy_set_header   X-Real-IP         \$remote_addr;
          proxy_pass http://127.0.0.1:3000;
      }
    }
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐