nginx反向代理jenkins-实现隐藏端口号

jenkins隐藏端口号-nginx方式

由于公司要求不必要的端口不要开放出来,jenkins的端口需要隐藏起来,之前有改过后来忘了怎么配,于是又一顿搜索后,决定把它记录下来!

1.修改nginx 的config文件 (默认是在/etc/nginx/nginx.conf), 然后到要修改的server 中添加location


  upstream jenkins_server {
    server 127.0.0.1:8988;
  }

  server {
    listen 80;
    server_name 服务器域名;

    location /jenkins/ {
      proxy_http_version 1.1; ## For websocket
      proxy_set_header Upgrade $http_upgrade; ## For websocket
      proxy_set_header Connection "upgrade"; ## For websocket
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Nginx-Proxy true;

      #rewrite /jenkins/(.*)/$1 break;
      proxy_pass http://jenkins_server;
    }

  }

2.修改jenkins的配置文件,在centos系统中,位于/etc/sysconfig/jenkins,在JENKINS_ARGS中追加prefix

  ...
  JENKINS_ARGS="--prefix=/jenkins"
  ...

3.检验配置文件是否正确

  sudo nginx -t

 

4.重启nginx ,重启jenkins

  nginx -s reload   

  service jenkins restart

5.修改jenkins配置

访问jenkins页面,修改系统配置,否则会提示反向代理配置错误 

 

posted @ 2019-07-04 20:13  iSunXiaoXiao  阅读(1360)  评论(0编辑  收藏  举报