您的位置:首页 > 运维架构 > 反向代理

使用nginx反向代理jenkins

2017-04-24 11:19 239 查看
1.在Jenkins 官方网站(http://jenkins-ci.org/)下载最新版本war包。拷贝到 $TOMCAT_HOME/webapps 下(不用解压)。启动tomcat服务。

2.找到nginx的配置文件,如nginx默认配置文件路径在/usr/local/nginx/conf/nginx.conf。

3.打开nginx.conf配置文件:sudo vim /usr/local/nginx/conf/nginx.conf

4. 修改配置文件

#user nobody;

worker_processes 1;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

#keepalive_timeout 0;

keepalive_timeout 65;

server {

listen 80;

server_name localhost;

#access_log /var/log/jenkins_access_log main;

#error_log /var/log/jenkins_error_log debug_http;

client_max_body_size 60M;

client_body_buffer_size 512k;

location / {

proxy_pass http://localhost:8080/;
proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

}

将红色字体部分加入到配置文件中。

5.重启nginx服务

service nginx start

6.访问jenkins页面
http://locallhost/jenkins
这样就可以访问到jenkins了,当然我们现在和直接访问jenkins(http://localhost:8080/jenkins)的区别是少了端口号,这是因为我们在同一台机器上,无法直接体现出jenkins的反向代理功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: