我正在使用 nginx 访问 IDM,但不知何故 css 和 js 文件无法正确重定向。我在 nginx 中的配置如下:
location /idm/{
proxy_pass https://keyrock-host:keyrock-port/;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/$ $1/idm/$2 redirect;
}
但它还不能正常工作。
更新 1:
172.16.40.7 - - [2019-04-01T11:34:01+00:00] "GET /stylesheets/bootstrap-select.min.css HTTP/1.1" 404 564 "https://172.30.66.248/key/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "-" "0.000" "-" "-"
2019/04/01 11:34:01 [error] 15#15: *9 open() "/etc/nginx/html/javascripts/tour.js" failed (2: No such file or directory), client: 172.16.40.7, server: , request: "GET /javascripts/tour.js HTTP/1.1", host: "172.30.66.248", referrer: "https://172.30.66.248/idm/"
172.16.40.7 - - [2019-04-01T11:34:01+00:00] "GET /javascripts/tour.js HTTP/1.1" 404 564 "https://172.30.66.248/idm/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "-" "0.000" "-" "-"
2019/04/01 11:34:01 [error] 15#15: *9 open() "/etc/nginx/html/javascripts/others/see_password.js" failed (2: No such file or directory), client: 172.16.40.7, server: , request: "GET /javascripts/others/see_password.js HTTP/1.1", host: "172.30.66.248", referrer: "https://172.30.66.248/idm/"
172.16.40.7 - - [2019-04-01T11:34:01+00:00] "GET /javascripts/others/see_password.js HTTP/1.1" 404 564 "https://172.30.66.248/idm/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36" "-" "0.000" "-" "-"
显示未找到文件:
*9 open() /etc/nginx/html/javascripts/others/see_password.js"
更新 2:直接访问后端应用程序并观察其行为。
URL : 172.30.66.235:3443 ---> Home Page
After Login : 172.30.66.235:3443/idm
(During Login if I click anywhere, /idm remains appended to it and after logging out.)
URL after Log out : 172.30.66.235:3443 ; similar to homepage.
执行相同操作的代码行是:
https://github.com/ging/fiware-idm/blob/7.5.1/routes/web/index.js#L23
或者您可以访问以下链接:https://account.lab.fiware.org/(Keyrock 的全球实例)
答案1
添加新server
块时,它应该看起来像这样。因此,您只需调用不同的名称/IP 即可转发/
到后端服务器的同一位置/
。您应该替换名称server_name
以及证书文件。
server {
server_name subdomain.example.com;
listen 443 ssl http2;
ssl_certificate /etc/nginx/your_certificate.pem;
ssl_certificate_key /etc/nginx/your_certificate.key;
location / {
proxy_set_header X-Forwarded-Host $host;
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_pass https://172.30.66.235:3443;
}
}
答案2
请尝试:
location /idm/ {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/idm(/.*)$ $1 break;
proxy_pass https://172.30.66.235:3443;
proxy_redirect / /idm/;
sub_filter '="/' '="/idm/';
sub_filter '= "/' '= "/idm/';
sub_filter '=\'/' '=\'/idm/';
sub_filter_once off;
}
编辑 1:添加proxy_redirect
编辑 2:添加sub_filter
选项
编辑 3:更改sub_filter
为用新位置替换所有可能发生的情况。
一个更好的方法可能是nginx_substitutions_filter以及正确的正则表达式。