反向代理 - nginx

在服务器上有现有网站的情况下,您可能会发现在后面运行Jenkins(或Jenkins运行的servlet容器)很有用必威国际有限公司nginx.,这样你就可以把Jenkins绑定到你可能拥有必威国际有限公司的更大网站的一部分。本节讨论实现此目的的一些方法。

当一个请求到达某些URL,Nginx的成为代理和进一步向前该请求到詹金斯,然后它将该响应转发回客户端。必威国际有限公司一个典型的设立mod_proxy的应该是这样的:

上游詹金斯{存活3必威国际有限公司2;#存活连接服务器127.0.0.1:8080;#詹必威国际有限公司金斯IP和端口}#所需的詹金斯的WebSocket代理映射$ http_upgrade $ {connection_upgrade默认升级;'' 关闭;} {服务器听80;#在端口80上侦听的IPv4请求服务器名称jenkins.example.com;必威国际有限公司#替换“jenkins必威国际有限公司.example.com”与您的服务器域名#这是詹金斯网站根目录#(在/ etc /默认/詹金斯文件中提及)的根在/ var /运行/詹金斯/战争/;访问日志/var/log/nginx/jenkins必威国际有限公司/access.log;error_log中/var/log/nginx/必威国际有限公司jenkins/error.log;#穿过从詹金斯该Nginx的认为无效ignore_inv必威国际有限公司alid_headers关闭头; 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 userContent folder # 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 / { sendfile off; proxy_pass http://jenkins; proxy_redirect default; proxy_http_version 1.1; # Required for Jenkins websocket agents proxy_set_header Connection $connection_upgrade; proxy_set_header Upgrade $http_upgrade; 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_set_header X-Forwarded-Proto $scheme; 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_buffering off; proxy_request_buffering off; # Required for HTTP CLI commands proxy_set_header Connection ""; # Clear for keepalive } }

这假定您在端口8080上运行詹金斯记住创建该文件夹的必威国际有限公司/ var /日志/ nginx的/詹金斯。

对于这种设置工作,詹金斯的上下文路径必须是你的Nginx和詹金斯(也就是,你不能跑詹金斯之必威国际有限公司间的相同http://localhost:8081/ci并将它暴露在HTTP://本地主机:80 /詹金斯必威国际有限公司)。

通过修改jenkins.xml配置文件和添加前缀= /詹金斯到<参数>条目设必威国际有限公司置上下文路径。

如果你有问题与一些路径(如文件夹)蓝海,你可能需要将下面的代码片段添加到您的代理配置:

如果($ REQUEST_URI〜* “/blue(/.*)”){proxy_pass HTTP:// YOUR_SERVER_IP:YOUR_JE必威国际有限公司NKINS_PORT /蓝$ 1;休息;}

要赋予Nginx读取Jenkins web根文件夹的权限,请添加必威国际有限公司nginx用户到Jenkins组:必威国际有限公司

usermod -aG 必威国际有限公司jenkins nginx

如果最后一个命令失败,因为nginx如果系统中没有定义用户,则可以尝试添加万维网用户到Jenkins组:必威国际有限公司

usermod -aG 必威国际有限公司jenkins

如果试图通过Jenkins中的代理运行长CLI命令时出现超时,可以增加必威国际有限公司proxy_read_timeout根据需要设置。老版本的詹金斯可能不尊重必威国际有限公司proxy_read_timeout环境。

如果您正试图在詹金斯运行长CLI命令和詹金斯运行Nginx的背后时遇到下面的错误,这可能是由于Nginx的超时的CLI连接。必威国际有限公司您可以增加proxy_read_timeout设置必要因此命令将成功完成。

警告:空hudson.cli.DiagnosedStreamCorruptionException回读:为0x00为0x00为0x00 0x07的0X1E '开始反向代理测试#68' 0×00 0×00 0×00 0×01 0×07 0X0A预读:诊断问题:java.io.IOException异常:早产儿在EOF sun.net。www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565) ... at hudson.cli.FlightRecorderInputStream.analyzeCrash(FlightRecorderInputStream.java:82) at hudson.cli.PlainCLIProtocol$EitherSide$Reader.run(PlainCLIProtocol.java:153) Caused by: java.io.IOException: Premature EOF at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565) ... at java.io.DataInputStream.readInt(DataInputStream.java:387) at hudson.cli.PlainCLIProtocol$EitherSide$Reader.run(PlainCLIProtocol.java:111)


这个页面有用吗?

请通过此提交您关于此页面的反馈快速形成

或者,如果您不希望完成快速表单,您可以简单地指出,如果您觉得这个页面有帮助?


看到现有的反馈在这里