Nginx

代理 IDM 的 Nginx 配置問題

  • April 8, 2019

我正在使用 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 的全球實例)

添加新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;
       }
}

引用自:https://serverfault.com/questions/960398