在ec2上jenkins的Nginx配置

时间:2017-09-07 03:40:48

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

我通过在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我得到的网站无法到达页面...

1 个答案:

答案 0 :(得分:2)

这里不需要

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

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

Jenkins conf文件

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;";
  }
}