【问题标题】:OpenShift - nginx pod as SSL termination and load balancerOpenShift - nginx pod 作为 SSL 终止和负载均衡器
【发布时间】:2019-09-25 10:43:58
【问题描述】:

过去,我在 Ubuntu 上为 nginx 使用了以下配置文件。它执行以下操作:

  1. SSL 终止
  2. 负载平衡器
  3. 插入自定义标题X-Nginx-header
  4. 记录调用
events { }

http {
    log_format main '$time_iso8601 - $remote_addr - "$http_user_agent" - "$request" - $request_id '
    '- $status - $body_bytes_sent - $request_time ';

    access_log /home/ubuntu/project-demo/logs/access.log main;
    error_log /home/ubuntu/project-demo/logs/error.log error;
    proxy_cache_path /data/nginx/cache keys_zone=one:10m;

    upstream demoapp {
        least_conn;
        server localhost:3001;
        server localhost:3002;
        server localhost:3003;
        server localhost:3004;
    }

    server {
        listen 443 ssl;

        ssl_certificate         /home/ubuntu/project-demo/certs/server.crt;
        ssl_certificate_key     /home/ubuntu/project-demo/certs/server.pem;
        ssl_protocols           TLSv1.1 TLSv1.2;
        ssl_ciphers             HIGH:!aNULL:!MD5;
        ssl_session_cache       shared:SSL:20m;
        ssl_session_timeout     4h;

        location / {
            proxy_set_header X-Nginx-header $request_id;
            proxy_pass http://demoapp/;
        }
    }
}

我想通过在 OpenShift 集群中部署为 pod 的 nginx 复制相同的内容。我可以看到 OpenShift 集群目录中列出的 nginx。当我尝试启动一个时,它会显示一个带有示例存储库的 GitHub 存储库字段 - https://github.com/sclorg/nginx-ex.git

我如何利用这个存储库来存储上面显示的配置文件?

【问题讨论】:

    标签: nginx openshift reverse-proxy kubernetes-pod


    【解决方案1】:

    这个镜像的nginx 1.14版本的文档可以找到here

    这是s2i 图片。 s2i 是一种构建机制,它采用源代码(在您的情况下为 nginx 配置)和基本 s2i 映像(在您的情况下为 sclorg nginx contianer 映像)并生成运行时映像(在您的情况下为带有配置的 nginx 映像)。

    基于该 nginx s2i 映像的上述文档,如果您将 s2i 构建过程指向 VCS 存储库(或本地目录),其中包含以下任何文件,那么 nginx s2i 构建器映像将自动使用它们以生成一个配置好的运行时容器镜像。

    ./nginx.conf-- The main nginx configuration file
    
    ./nginx-cfg/*.conf
    Should contain all nginx configuration we want to include into image
    
    ./nginx-default-cfg/*.conf
    Contains any nginx config snippets to include in the default server block
    
    ./nginx-start/*.sh
    Contains shell scripts that are sourced right before nginx is launched
    
    ./
    Should contain nginx application source code
    

    在您的情况下,这意味着您可以将您的配置放在 nginx.conf 文件中以覆盖整个 nginx 配置,或者放在 ./nginx-cfg/*.conf 文件中以将您的配置添加到默认的 nginx.conf 文件中。

    【讨论】:

    • 我从oc new-app centos/nginx-112-centos7~https://github.com/user/repo.git 开始,repo 的根有nginx.conf。但是,我没有看到它包含在 pod 中,并且 pod 永远处于运行状态,没有日志。
    • s2i 构建的日志是什么? assemble 脚本应该在构建过程中输出信息,让您知道它是否选择了您的文件。您还应该能够在正在运行的容器 here 中找到该文件。
    • 我在根文件夹中使用nginx.conf,如下所示 - pastebin.com/yr0jNKyk。使用new-app 命令,构建日志(oc logs -f bc/repo)显示推送成功。部署似乎没有完成...
    • 看起来您的运行时映像无法启动。首先我要检查的是 nginx 是否在运行时映像中启动以及配置是否良好。
    • 如果你在 OpenShift 中部署它,Pod 在崩溃之前会有日志。您可以在 UI 内部或通过oc get logs <pod-id> 查看
    猜你喜欢
    • 1970-01-01
    • 2016-06-04
    • 2023-04-09
    • 1970-01-01
    • 2016-11-10
    • 2020-06-28
    • 2020-10-22
    • 2017-04-01
    • 2018-02-21
    相关资源
    最近更新 更多