使用nginx反向代理jenkins


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的反向代理功能。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM