【问题标题】:Nginx configuration for jenkins on ec2ec2 上 jenkins 的 Nginx 配置
【发布时间】:2018-02-15 15:58:26
【问题描述】:

我通过在 ec2 上设置构建服务器来学习 nginx 和 jenkins。设置 jenkins 很容易,我什至可以创建一个测试作业。我现在想继续进行 nginx 配置,并且对如何设置它感到非常困惑。我用我的域托管了区域,我们称之为 domain.com 。我为 jenkins.domain.com 创建了一条 A 记录,并在值框中输入了 ec2 实例的 IP。

然后将其添加到 /etc/nginx/site-enabled/default

server {
    listen 80;
    server_name jenkins.domain.com;
    return 301 https://$host$request_uri;
}

server {

    listen 80;
    server_name jenkins.domain.com;

    location / {

      proxy_set_header        Host $host:$server_port;
      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 $scheme;

      # Fix the "It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://127.0.0.1:8080;
      proxy_read_timeout  90;

      proxy_redirect      http://127.0.0.1:8080 https://jenkins.domain.com;

      # Required for new HTTP-based CLI
      proxy_http_version 1.1;
      proxy_request_buffering off;
      # workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
      add_header 'X-SSH-Endpoint' 'jenkins.domain.com:50022' always;
    }
  }

但是,当我转到 jenkins.domain.com:80 时,我得到该站点无法访问页面...

【问题讨论】:

  • 您的意思是将所有请求重定向到 SSL 吗?您没有配置 SSL 侦听器。
  • 我按照本教程生成了自签名 SSL 证书 - digitalocean.com/community/tutorials/…
  • 您可能已经生成了证书,但您仍然没有配置 SSL 侦听器,这可能是您的问题的一部分。如果您注释掉配置的第一部分(执行 301 重定向的部分)并重新加载 nginx,那么会发生什么?你得到同样的错误吗? access.logerror.log 文件中的内容是什么?
  • 您正在将所有内容重定向到端口 443,而您的 nginx 配置文件中没有任何 SSL 配置。参考 - nginx.org/en/docs/http/configuring_https_servers.html

标签: amazon-web-services nginx jenkins amazon-ec2


【解决方案1】:

这里不需要proxy_redirect。您可以使用以下站点配置。您应该在 /etc/nginx/site-available(for ubuntu) 或 /etc/nginx/conf.d/ (centos 或 rhel) 中创建文件 jenkins 并复制该文件中的配置。您必须在启用站点的 Ubuntu 上创建软链接。

ln -s /etc/nginx/site-available/jenkins /etc/nginx/site-enabled/jenkins

Jenkins 配置文件

server {
  listen 80;
  server_name jenkins.domain.com;
    access_log /var/log/nginx-access.log;
    error_log /var/log/nginx-error.log;
  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;    
    proxy_read_timeout 150s;
    proxy_next_upstream error;
    proxy_pass http://127.0.0.1:8080;

    # Add HTTP Strict Transport Security for good measure.
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;";
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-31
    • 2019-01-19
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    相关资源
    最近更新 更多