0

I was working on accessing IDM using nginx, but somehow css and js files are not able to redirect properly.My configuration in nginx is as follows:

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;
}

But it is not working properly still.


Update 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" "-" "-"

It shows the files are not found : *9 open() /etc/nginx/html/javascripts/others/see_password.js"


Update 2: While accessing the backend application directly and observing the behaviour.

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.

The code line that does the same is :

https://github.com/ging/fiware-idm/blob/7.5.1/routes/web/index.js#L23

Or you can access the link : https://account.lab.fiware.org/ (Global instance of Keyrock)

2
  • $1 and $2 in your rewrite are backreferences to the regex. But your regex has no matching groups to be referenced at. Could you supply us with URLs and what they supposed to look like in the backend?
    – unNamed
    Mar 29 '19 at 7:43
  • Yes, for backend the url is : 172.30.66.235:3443 on (HTTPs) and the IP for nginx should be 172.30.66.248/idm (on HTTPs) while accessing idm.
    – Tsh
    Apr 1 '19 at 4:43
0

When adding a new server block it should look like this. So you forward / to the same location / of your backend server just by calling a different name/IP. You should replace the name in server_name as well as the certificate files.

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
  • Sir, actually the requirement resists me from running this on root.However, the one which you have written on location / above makes it run in the earlier scenario also. But I need to have /idm/ with the URL appended everytime. You can check the working of IDM on account.lab.fiware.org . The one on my local creates the same url after logging in and after logging out. Additionally, at code level when the user session is acquired it appends /idm to it only after logging in. github.com/ging/fiware-idm/blob/master/routes/web/index.js#L22
    – Tsh
    Apr 4 '19 at 6:42
  • Also,if I remove the rewrite ^/idm(/.*)$ $1 break; in configuration and keeping the proxy_redirect, it still doesn't works. is it possible can we have a direct chat??
    – Tsh
    Apr 4 '19 at 6:45
1

Please try:

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;

}

Edit 1: Added proxy_redirect

Edit 2: Added sub_filter options

Edit 3: Changed sub_filter to replace all possible occurrences with the new location.

A nicer way would probably be nginx_substitutions_filter and a proper regex.

15
  • Hi Sir, it's not working still. While looking at the console in web-browser i get : GET 172.30.66.248/javascripts/tour.js net::ERR_ABORTED 404 (Not Found) for (approx. 25 files) that are mostly css and js. whereas, while accessing 172.30.66.248/idm/javascripts/tour.js shows the content of file.
    – Tsh
    Apr 1 '19 at 9:55
  • I've added proxy_redirect, try it pls.
    – unNamed
    Apr 1 '19 at 12:51
  • Hi Sir, Still no success. IDM being a nodejs application github.com/ging/fiware-idm is still not loading css or js only.
    – Tsh
    Apr 2 '19 at 5:09
  • I've added sub_filter options, pls try again :x
    – unNamed
    Apr 2 '19 at 9:24
  • hi Sir, bingo! the first page gets loaded but after logging in or clicking on sign in or sign up it shows 404 Not found, but if I write idm in the url it displays. So, in these cases its not working, but from earlier, its loading all the css and js for front page.
    – Tsh
    Apr 2 '19 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.