我在Docker里面运行Jenkins,后面是一个Nginx反向代理。现在我遇到了旋转变压器的问题。
当我用:
激活解析器时set $backend "http://jenkins:8080/";
proxy_pass $backend;
我将收到所有javascript文件的以下错误:
Refused to execute script from 'http://localhost/static/....js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
当我只是在没有解析器的情况下代理传递:
proxy_pass http://jenkins:8080/;
它有效,但没有解析器。解析器是强制性的,否则当主机jenkins
更改它的Ip(Docker DNS服务器)时,设置将无效。
我的配置:
resolver 127.0.0.11 ipv6=off valid=30s;
client_max_body_size 100m;
keepalive_timeout 65;
types_hash_max_size 2048;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
set $backend "http://jenkins:8080/";
proxy_pass $backend;
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;
}
}
答案 0 :(得分:1)
Based on the error message you receive, it sounds like you're getting HTML pages in place of JavaScript.
Using a proxy_pass
paradigm with a variable, you're telling nginx that it shouldn't mess with the value any further, e.g., regardless of the location
and the URI, all requests to your backend will always be just as the variable says (e.g., with the same URI in your case).
The best option would probably be to use $uri
, $is_args
and $args
, as per NGINX proxy_pass remove path prefix & resolve DNS:
- set $backend "http://jenkins:8080/";
- proxy_pass $backend;
+ proxy_pass http://jenkins:8080$uri$is_args$args;
Another option, which potentially could be less secure, is to use $uri_request
, which has a slightly different meaning than the plain $uri
in certain limited cases, as per Nginx pass_proxy subdirectory without url decoding:
proxy_pass http://jenkins:8080$request_uri;