0

So i am trying to do a routing to 3 differents containers based on the request using docker and Nginx. The containers have the same IP and different ports. here is the Nginx configuration :

upstream helpdesk{
    server 10.10.10.20:8089;
}

upstream dsi_helpdesk{
    server 10.10.10.20:8088;
}

upstream drh_helpdesk{
    server 10.10.10.20:8090;
}

server {

    listen       80;
    server_name  myticket.grgsh.com;


    location / {
        proxy_set_header Host $host;
        proxy_pass http://helpdesk;
    }

    location /dsi {
        proxy_set_header Host $host;
        proxy_pass http://dsi_helpdesk;
    }

    location /drh {
        proxy_set_header Host $host;
        proxy_pass http://drh_helpdesk;
    }

}

when i navigate to myticket.grgsh.com the server redirect me to the upstream helpdesk but when i navigate to myticket.grgsh.com/dsi or myticket.grgsh.com/drh i get the error :

Not Found The requested URL was not found on this server.

Can anyone help resolve this problem ? Thanks.

Amy Murphy
  • 1,003
  • 1
  • 5
  • 10
  • The upstream name is ```helpdesk``` but in your ```proxy_pass``` you are passing it to ```all_helpdesk```. Is that a typo in posting the question or do you really have this configuration? – Yogeshwar Singh Dec 26 '19 at 12:43
  • @Yogeshwar it was an error in posting the question, i am sorry i fixed it. – Amy Murphy Dec 26 '19 at 12:46
  • Do you see the requests to ```myticket.grgsh.com/dsi``` or ```myticket.grgsh.com/drh``` in the nginx logs? I mean did you check if the nginx is throwing the 404 or is it the upstream server? Because the nginx configuration looks okay to me. – Yogeshwar Singh Dec 26 '19 at 12:50
  • @Yogeshwar here is the docker log `10.1.12.130 - - [26/Dec/2019:13:57:05 +0000] "GET /drh HTTP/1.1" 404 196 "http://myticket.grgsh.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0" "-` – Amy Murphy Dec 26 '19 at 13:57
  • The logs aren't very clear, please add more details to the log by modifying log format. Try this : https://stackoverflow.com/a/26299679/2313097 – Yogeshwar Singh Dec 26 '19 at 14:38
  • we need the complete URI and the upstream address selected by nginx to debug this issue. If you do not want to modify the log format than try returning from location blocks like this: ``` location /dsi { return 200 'this dsi path!'; } location /drh { return 200 'this drh path!'; }``` – Yogeshwar Singh Dec 26 '19 at 14:39
  • @Yogeshwar hey there, when i tried the last one it returned a file named ```dsi or drh``` containing ```"this dsi path!" or "this drh path"``` – Amy Murphy Dec 29 '19 at 13:10
  • Do you mean when you hit ```myticket.grgsh.com/dsi``` it returned ```this dsi path!```. If yes, then you should check th upstream applications. Request is going to the upstream but upstream is throwing 404. Also you should revert the nginx conf back to what it was before this change. – Yogeshwar Singh Dec 29 '19 at 13:21
  • @Yogeshwar yes when i hit ```myticket.grgsh.com/dsi```, and i just modified the logs: here is the output: ```[29/Dec/2019:13:21:29 +0000] 10.1.12.142 - - - myticket.grgsh.com myticket.grgsh.com to:10.10.10.51:80: GET /dsi HTTP/1.1 404 upstream_response_time0.000 msec 1577625689.579 request_time 0.001``` ```[29/Dec/2019:13:21:35 +0000] 10.1.12.142 - - - myticket.grgsh.com myticket.grgsh.com to:10.10.10.20:8090: GET /drh HTTP/1.1 404 upstream_response_time0.016 msec 1577625695.375 request_time 0.014``` – Amy Murphy Dec 29 '19 at 13:23
  • As you can see in the logs it has correctly selected the upstream 10.10.10.20:8090. So you should check the application hosted at 10.10.10.20:8090. That application might be throwing 404. – Yogeshwar Singh Dec 29 '19 at 13:27
  • @Yogeshwar I found the solution This ```location /dsi { proxy_pass http://backend; }``` Needs to be this ```location /dsi/ { proxy_pass http://dsi_helpdesk/; }``` – Amy Murphy Dec 29 '19 at 13:41
  • Oh, wow... Cool!! :) I think you can keep it ```location /dsi { proxy_pass http://dsi_helpdesk/; }``` – Yogeshwar Singh Dec 29 '19 at 13:57
  • @Yogeshwar i got another problem i keep getting the webpage without css, i posted the logs output in another answer bellow this comment. do you knwo why this is happening ? thanks for your help – Amy Murphy Dec 29 '19 at 14:23
  • Check the calls that webpage making for css files? Check the network logs. See if you are able to hit that url and get the css files. You will probably get some error. – Yogeshwar Singh Dec 29 '19 at 14:36

2 Answers2

1

The solution is:

This

location /dsi {
    proxy_set_header Host $host;
    proxy_pass http://dsi_helpdesk;
}

Needs to be this

location /dsi/ {
    proxy_set_header Host $host;
    proxy_pass http://dsi_helpdesk/;
}
Amy Murphy
  • 1,003
  • 1
  • 5
  • 10
0

After fixing the first problem, i got another one, so agter redirecting to myticket.grgsh.com/dsi, the web page that i get are without css or icons, here is the logs output:

 [29/Dec/2019:14:03:56 +0000] 10.1.12.142 - - - myticket.grgsh.com myticket.grgsh.com to:10.10.10.51:80: GET /dsi HTTP/1.1 200 upstream_response_time0.028 msec 1577628236.505 request_time 0.033
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /css/styles.css HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /css/palettes/flood.min.css?v=9.3.1 HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /lib/font-awesome-4.7.0/css/font-awesome.min.css?v=9.3.1 HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /lib/jqueryplugins/select2/js/select2.full.js?v=9.3.1 HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /lib/jquery/js/jquery-1.10.2.min.js?v=9.3.1 HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /lib/jqueryplugins/select2/css/select2.min.css?v=9.3.1 HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /js/common.min.js?v=9.3.1 HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
    10.1.12.142 - - [29/Dec/2019:14:03:56 +0000] "GET /front/cron.php HTTP/1.1" 404 196 "http://myticket.grgsh.com/dsi" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)" "-"
Amy Murphy
  • 1,003
  • 1
  • 5
  • 10