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.

最新文章

  1. Mybatis中javaType和jdbcType对应关系
  2. Java集合类学习笔记(各种Map实现类的性能分析)
  3. javascript的document.execCommand(转)
  4. 无可匹敌的创建job(细化很多细节)
  5. Python 更改cmd中的字色
  6. 复习css3的部分属性
  7. I/O浅析
  8. Magento首页显示产品
  9. css清除浮动大全,共8种方法
  10. Cookie中文乱码问题
  11. 用原生js简单模仿angular的依赖注入
  12. PLSQL设置细节
  13. 【Java每日一题】20170306
  14. python删除列表元素
  15. Just oj 2018 C语言程序设计竞赛(高级组)H: CBT?
  16. Linux Shell 简介
  17. WebSocket原理与实践(三)--解析数据帧
  18. sklearn模块函数介绍
  19. 低版本系统兼容的ActionBar(七)自定义Actionbar标题栏字体
  20. SQL学习之SqlMap SQL注入

热门文章

  1. react-native 报错
  2. apollo配置相关
  3. LOJ 10160 - 「一本通 5.2 练习 3」周年纪念晚会 / 没有上司的晚会
  4. fullcalendar插件日程管理
  5. ZooKeeper与Eureka对比
  6. 使用Django简单编写一个XSS平台
  7. 既使用maven编译,又使用lib下的Jar包
  8. 通过css属性hack完成select样式美化,并兼容IE
  9. View初探
  10. [ 转载 ] Tcp三次握手和四次挥手详解