将YAML转换为JSON时出错:yaml:找不到预期的密钥

时间:2019-08-06 07:18:17

标签: kubernetes yaml configmap

我从在线教程中复制并粘贴了configMap文件,尝试应用该文件时弹出错误。这是文件:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: nginx-config
      labels:
        tier: backend
    data:
      config : |
        server {
          index index.php index.html;
          error_log  /var/log/nginx/error.log;
          access_log /var/log/nginx/access.log;

          root /dir;

          location / {
              try_files $uri $uri/ /index.php?$query_string;
          }

          location ~ .php$ {
              try_files $uri =404;
              fastcgi_split_path_info ^(.+.php)(/.+)$;
              fastcgi_pass php:9000;
              fastcgi_index index.php;
              include fastcgi_params;
              fastcgi_param SCRIPT_FILENAME                 
              $document_root$fastcgi_script_name;
              fastcgi_param PATH_INFO $fastcgi_path_info;
          }
       }

这是错误: 第28行:找不到预期的密钥

2 个答案:

答案 0 :(得分:0)

应该是:

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
  labels:
    tier: backend
data:
  config : |
    server {
      index index.php index.html;
      error_log  /var/log/nginx/error.log;
      access_log /var/log/nginx/access.log;

      root /dir;

      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }

      location ~ .php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+.php)(/.+)$;
          fastcgi_pass php:9000;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME                 
          $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
           }
       }

答案 1 :(得分:0)

下一行的

文本对齐方式不正确。编辑了您的问题并更正了格式。现在试试。它应该工作

$document_root$fastcgi_script_name;