Running Jenkins behind Nginx

简介: original : https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Nginx In situations where you have existing web sites on your server, y...

original : https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Nginx

In situations where you have existing web sites on your server, you may find it useful to run Jenkins (or the servlet container that Jenkins runs in) behind Nginx, so that you can bind Jenkins to the part of a bigger website that you may have. This document discusses some of the approaches for doing this.

When a request arrives for certain URLs, Nginx becomes a proxy and further forward that request to Jenkins, then it forwards the response back to the client. A typical set up for mod_proxy would look like this:

server {
  listen          80;       # Listen on port 80 for IPv4 requests

  server_name     jenkins.example.com;

  #this is the jenkins web root directory (mentioned in the /etc/default/jenkins file)
  root            /var/run/jenkins/war/;

  access_log      /var/log/nginx/jenkins/access.log;
  error_log       /var/log/nginx/jenkins/error.log;

  location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {

    #rewrite all static files into requests to the root
    #E.g /static/12345678/css/something.css will become /css/something.css
    rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
  }

  location /userContent {
        #have nginx handle all the static requests to the userContent folder files
        #note : This is the $JENKINS_HOME dir
	root /var/lib/jenkins/;
        if (!-f $request_filename){
           #this file does not exist, might be a directory or a /**view** url
           rewrite (.*) /$1 last;
	   break;
        }
	sendfile on;
  }

  location @jenkins {
      sendfile off;
      proxy_pass         http://127.0.0.1:8080;
      proxy_redirect     default;

      proxy_set_header   Host             $host;
      proxy_set_header   X-Real-IP        $remote_addr;
      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
      proxy_max_temp_file_size 0;

      #this is the maximum upload size
      client_max_body_size       10m;
      client_body_buffer_size    128k;

      proxy_connect_timeout      90;
      proxy_send_timeout         90;
      proxy_read_timeout         90;

      proxy_buffer_size          4k;
      proxy_buffers              4 32k;
      proxy_busy_buffers_size    64k;
      proxy_temp_file_write_size 64k;
}

  location / {

     # Optional configuration to detect and redirect iPhones
      if ($http_user_agent ~* '(iPhone|iPod)') {
          rewrite ^/$ /view/iphone/ redirect;
      }

      try_files $uri @jenkins;
   }
}

This assumes that you run Jenkins on port 8080. Remember to create the folder /var/log/nginx/jenkins.

目录
相关文章
|
6月前
|
jenkins 应用服务中间件 持续交付
Git + Jenkins 自动化 NGINX 发布简易实现
Git + Jenkins 自动化 NGINX 发布简易实现
|
6月前
|
JavaScript jenkins 应用服务中间件
Jenkins + Github + Nginx 自动化部署 Vue 项目
Jenkins + Github + Nginx 自动化部署 Vue 项目
393 0
|
Java jenkins 应用服务中间件
Jenkins+Gitlab+Nginx+Maven编译Java项目自动发布与基于tag版本回退(重复构建问题已解决)
Jenkins+Gitlab+Nginx+Maven编译Java项目自动发布与基于tag版本回退(重复构建问题已解决)
113 0
|
jenkins 应用服务中间件 持续交付
Jenkins+Gitlab+Nginx实现自动发布与回退基于tag版本的静态项目(解决重复构建问题)
Jenkins+Gitlab+Nginx实现自动发布与回退基于tag版本的静态项目(解决重复构建问题)
224 0
|
缓存 资源调度 前端开发
一步步实现Nginx +Docker + Jenkins前端自动化部署
一步步实现Nginx +Docker + Jenkins前端自动化部署
706 1
|
JavaScript jenkins 应用服务中间件
nginx+jenkins部署git前端项目
从 tomcat 到 github Page,再到 nginx。技术在变化,但搭建个人站点的执念没有中断。 与你同行!
|
JavaScript 前端开发 jenkins
Jenkins + Github + Nginx 自动化部署 Vue 项目
Jenkins + Github + Nginx 自动化部署 Vue 项目,看起来好像 Jenkins 非常复杂,但其实只要自己多实操几次,一次又一次的去想如何偷懒,你就可以一步一步发现更多的知识点。
816 0
Jenkins + Github + Nginx 自动化部署 Vue 项目
|
jenkins Java 应用服务中间件
使用Jenkins持续集成前端项目并自动化部署到Nginx服务器
上午折腾了一下Jenkins持续集成,由于公司使用自己搭建的svn服务器来进行代码管理,因此这里Jenkins是针对svn服务器来进行的配置,后面稍微介绍了下针对Github管理的项目的Jenkins配置 之前项目每次修改之后都需要本地npm run build一次手动发布到服务器上方便测试和产品查看,有了Jenkins持续集成之后只要svn或者git提交之后就会自动打包,很方便,此次记录以备后询。 声明: 后面的项目地址与打包地址都是使用em-mes,自行修改; 另外还有路径等,根据自己情况自行修改; 感兴趣的同学可以加文末的微信群,一起讨论吧~
使用Jenkins持续集成前端项目并自动化部署到Nginx服务器
|
jenkins 应用服务中间件 持续交付
|
19天前
|
应用服务中间件 BI nginx
Nginx的location配置详解
【10月更文挑战第16天】Nginx的location配置详解