使用nginx反向代理jenkins

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

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

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

4. 修改配置文件tomcat


#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;app


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

}
webapp


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

5.重启nginx服务网站

service nginx startspa

6.访问jenkins页面debug

http://locallhost/jenkins

这样就能够访问到jenkins了,固然咱们如今和直接访问jenkins(http://localhost:8080/jenkins)的区别是少了端口号,这是由于咱们在同一台机器上,没法直接体现出jenkins的反向代理功能。

相关文章
相关标签/搜索