[NGINX loadbalancing] error 404 but backend work fine

Hello all,

I try to load balance my web app  using  nginx but  I get 404 instead my app.
All my backend (MS IIS) work fine when  I try to query directely.

Here is screeshot of headers when I query my bakend directely

Headers
Here is my nginx config that return 404

upstream mywebapp {
    ip_hash;
    server 10.236.10.21:80;
    server 10.236.10.22:80;
    server 10.236.10.23:80;
    server 10.236.10.24:80;
    server 10.236.10.25:80;
    server 10.236.10.26:80;
    keepalive 16;
    }
    server {
    listen 443 ssl;
    server_name  test.mywebapp.fr;
    #client_max_body_size  10m;
    ssl  on;
    
   location / {
   proxy_pass  http://mywebapp;
   proxy_http_version 1.1;
   proxy_set_header        X-Forwarded-For    $proxy_add_x_forwarded_for;
   proxy_set_header        X-Forwarded-Host   $host:443;
   proxy_set_header        X-Forwarded-Server $host;
   proxy_set_header        X-Forwarded-Port   443;
   proxy_set_header        X-Forwarded-Proto  https;
   proxy_set_header       Connection "";
   proxy_set_header       Connection "";
   proxy_read_timeout   60m;
   proxy_pass_request_headers on;
  }
}

Open in new window




Can you help me please?
Georges OrwellSystem AdministratorAsked:
Who is Participating?
 
Georges OrwellSystem AdministratorAuthor Commented:
Hello

Finaly I found the root cause of my problem:

I had to replace this line

proxy_set_header        X-Forwarded-Host   $host:443;

Open in new window


By  this

proxy_set_header        X-Forwarded-Host   $host:80;

Open in new window


because indeed my IIS backend listen on 80 and SSL offloading is made by nginx.

Thank you for your help.
0
 
Zaheer IqbalTechnical Assurance & ImplementationCommented:
Is it because you are trying to https and your backend is configured for http ?
0
 
Georges OrwellSystem AdministratorAuthor Commented:
Yes but it work with others apps.
With one other app I use https to nginx and nginx forward to 8080.
0
 
Georges OrwellSystem AdministratorAuthor Commented:
here is full log

2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_do_handshake: -1
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_get_error: 2
2018/02/17 12:46:28 [debug] 15406#15406: *219 reusable connection: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL handshake handler: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_do_handshake: 1
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL: TLSv1.2, cipher: "ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD"
2018/02/17 12:46:28 [debug] 15406#15406: *219 reusable connection: 1
2018/02/17 12:46:28 [debug] 15406#15406: *219 http wait request handler
2018/02/17 12:46:28 [debug] 15406#15406: *219 malloc: 000055F8B85EC460:1024
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_read: -1
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_get_error: 2
2018/02/17 12:46:28 [debug] 15406#15406: *219 free: 000055F8B85EC460
2018/02/17 12:46:28 [debug] 15406#15406: *219 http wait request handler
2018/02/17 12:46:28 [debug] 15406#15406: *219 malloc: 000055F8B85EC460:1024
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_read: 399
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_read: -1
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_get_error: 2
2018/02/17 12:46:28 [debug] 15406#15406: *219 reusable connection: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 posix_memalign: 000055F8B85149E0:4096 @16
2018/02/17 12:46:28 [debug] 15406#15406: *219 http process request line
2018/02/17 12:46:28 [debug] 15406#15406: *219 http request line: "GET / HTTP/1.1"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http uri: "/"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http args: ""
2018/02/17 12:46:28 [debug] 15406#15406: *219 http exten: ""
2018/02/17 12:46:28 [debug] 15406#15406: *219 http process request header line
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Host: test.mywebapp.fr"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0"
2018/02/17 12:46:28 [debug] 15406#15406: *219 posix_memalign: 000055F8B85E8550:4096 @16
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Accept-Encoding: gzip, deflate, br"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Connection: keep-alive"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Upgrade-Insecure-Requests: 1"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Pragma: no-cache"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header: "Cache-Control: no-cache"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http header done
2018/02/17 12:46:28 [debug] 15406#15406: *219 event timer del: 3: 1518868048380
2018/02/17 12:46:28 [debug] 15406#15406: *219 generic phase: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 rewrite phase: 1
2018/02/17 12:46:28 [debug] 15406#15406: *219 test location: "/"
2018/02/17 12:46:28 [debug] 15406#15406: *219 using configuration "/"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http cl:-1 max:1048576
2018/02/17 12:46:28 [debug] 15406#15406: *219 rewrite phase: 3
2018/02/17 12:46:28 [debug] 15406#15406: *219 post rewrite phase: 4
2018/02/17 12:46:28 [debug] 15406#15406: *219 generic phase: 5
2018/02/17 12:46:28 [debug] 15406#15406: *219 generic phase: 6
2018/02/17 12:46:28 [debug] 15406#15406: *219 generic phase: 7
2018/02/17 12:46:28 [debug] 15406#15406: *219 access phase: 8
2018/02/17 12:46:28 [debug] 15406#15406: *219 access phase: 9
2018/02/17 12:46:28 [debug] 15406#15406: *219 access phase: 10
2018/02/17 12:46:28 [debug] 15406#15406: *219 post access phase: 11
2018/02/17 12:46:28 [debug] 15406#15406: *219 http init upstream, client timer: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 epoll add event: fd:3 op:3 ev:80002005
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "X-Forwarded-For: "
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script var: "192.168.184.254"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "
"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "X-Forwarded-Host: "
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script var: "test.mywebapp.fr"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: ":443"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "
"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "X-Forwarded-Server: "
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script var: "test.mywebapp.fr"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "
"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "X-Forwarded-Port: 443
"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "X-Forwarded-Proto: https
"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "Host: "
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script var: "mywebappw"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "
"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: "Connection: close
"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: ""
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: ""
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: ""
2018/02/17 12:46:28 [debug] 15406#15406: *219 http script copy: ""
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Accept-Encoding: gzip, deflate, br"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Upgrade-Insecure-Requests: 1"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Pragma: no-cache"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Cache-Control: no-cache"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header:
"GET / HTTP/1.1
X-Forwarded-For: 192.168.184.254
X-Forwarded-Host: test.mywebapp.fr:443
X-Forwarded-Server: test.mywebapp.fr
X-Forwarded-Port: 443
X-Forwarded-Proto: https
Host: mywebappw
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache

"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http cleanup add: 000055F8B85E8F48
2018/02/17 12:46:28 [debug] 15406#15406: *219 init keepalive peer
2018/02/17 12:46:28 [debug] 15406#15406: *219 get keepalive peer
2018/02/17 12:46:28 [debug] 15406#15406: *219 get ip hash peer, try: 6
2018/02/17 12:46:28 [debug] 15406#15406: *219 get ip hash peer, hash: 1 0002
2018/02/17 12:46:28 [debug] 15406#15406: *219 stream socket 14
2018/02/17 12:46:28 [debug] 15406#15406: *219 epoll add connection: fd:14 ev:80002005
2018/02/17 12:46:28 [debug] 15406#15406: *219 connect to 10.236.10.22:80, fd:14 #220
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream connect: -2
2018/02/17 12:46:28 [debug] 15406#15406: *219 posix_memalign: 000055F8B85E6E40:128 @16
2018/02/17 12:46:28 [debug] 15406#15406: *219 event timer add: 14: 60000:1518868048564
2018/02/17 12:46:28 [debug] 15406#15406: *219 http finalize request: -4, "/?" a:1, c:2
2018/02/17 12:46:28 [debug] 15406#15406: *219 http request count:2 blk:0
2018/02/17 12:46:28 [debug] 15406#15406: *219 http run request: "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream check client, write event:1, "/"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream request: "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream send request handler
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream send request
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream send request body
2018/02/17 12:46:28 [debug] 15406#15406: *219 chain writer buf fl:1 s:551
2018/02/17 12:46:28 [debug] 15406#15406: *219 chain writer in: 000055F8B85E8FE8
2018/02/17 12:46:28 [debug] 15406#15406: *219 writev: 551 of 551
2018/02/17 12:46:28 [debug] 15406#15406: *219 chain writer out: 0000000000000000
2018/02/17 12:46:28 [debug] 15406#15406: *219 event timer del: 14: 1518868048564
2018/02/17 12:46:28 [debug] 15406#15406: *219 event timer add: 14: 3600000:1518871588564
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream request: "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream process header
2018/02/17 12:46:28 [debug] 15406#15406: *219 malloc: 000055F8B85E9560:4096
2018/02/17 12:46:28 [debug] 15406#15406: *219 recv: eof:0, avail:1
2018/02/17 12:46:28 [debug] 15406#15406: *219 recv: fd:14 492 of 4096
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy status 404 "404 Not Found"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Content-Type: text/html; charset=us-ascii"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Server: Microsoft-HTTPAPI/2.0"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Date: Sat, 17 Feb 2018 11:51:15 GMT"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Connection: close"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header: "Content-Length: 315"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy header done
2018/02/17 12:46:28 [debug] 15406#15406: *219 HTTP/1.1 404 Not Found
Server: nginx/1.13.1
Date: Sat, 17 Feb 2018 11:46:28 GMT
Content-Type: text/html; charset=us-ascii
Content-Length: 315
Connection: keep-alive

2018/02/17 12:46:28 [debug] 15406#15406: *219 write new buf t:1 f:0 000055F8B85E92A0, pos 000055F8B85E92A0, size: 173 file: 0, size: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 http write filter: l:0 f:0 s:173
2018/02/17 12:46:28 [debug] 15406#15406: *219 http cacheable: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 http proxy filter init s:404 h:0 c:0 l:315
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream process upstream
2018/02/17 12:46:28 [debug] 15406#15406: *219 pipe read upstream: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 pipe preread: 315
2018/02/17 12:46:28 [debug] 15406#15406: *219 pipe buf free s:0 t:1 f:0 000055F8B85E9560, pos 000055F8B85E9611, size: 315 file: 0, size: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 pipe length: 315
2018/02/17 12:46:28 [debug] 15406#15406: *219 input buf #0
2018/02/17 12:46:28 [debug] 15406#15406: *219 pipe write downstream: 1
2018/02/17 12:46:28 [debug] 15406#15406: *219 pipe write downstream flush in
2018/02/17 12:46:28 [debug] 15406#15406: *219 http output filter "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http copy filter: "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 posix_memalign: 000055F8B85EA570:4096 @16
2018/02/17 12:46:28 [debug] 15406#15406: *219 http postpone filter "/?" 000055F8B85E9488
2018/02/17 12:46:28 [debug] 15406#15406: *219 write old buf t:1 f:0 000055F8B85E92A0, pos 000055F8B85E92A0, size: 173 file: 0, size: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 write new buf t:1 f:0 000055F8B85E9560, pos 000055F8B85E9611, size: 315 file: 0, size: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 http write filter: l:0 f:0 s:488
2018/02/17 12:46:28 [debug] 15406#15406: *219 http copy filter: 0 "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 pipe write downstream done
2018/02/17 12:46:28 [debug] 15406#15406: *219 event timer: 14, old: 1518871588564, new: 1518871588565
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream exit: 0000000000000000
2018/02/17 12:46:28 [debug] 15406#15406: *219 finalize http upstream request: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 finalize http proxy request
2018/02/17 12:46:28 [debug] 15406#15406: *219 free keepalive peer
2018/02/17 12:46:28 [debug] 15406#15406: *219 free rr peer 6 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 close http upstream connection: 14
2018/02/17 12:46:28 [debug] 15406#15406: *219 free: 000055F8B85E6E40, unused: 48
2018/02/17 12:46:28 [debug] 15406#15406: *219 event timer del: 14: 1518871588564
2018/02/17 12:46:28 [debug] 15406#15406: *219 reusable connection: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 http upstream temp fd: -1
2018/02/17 12:46:28 [debug] 15406#15406: *219 http output filter "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http copy filter: "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http postpone filter "/?" 00007FFE4DE85590
2018/02/17 12:46:28 [debug] 15406#15406: *219 write old buf t:1 f:0 000055F8B85E92A0, pos 000055F8B85E92A0, size: 173 file: 0, size: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 write old buf t:1 f:0 000055F8B85E9560, pos 000055F8B85E9611, size: 315 file: 0, size: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 write new buf t:0 f:0 0000000000000000, pos 0000000000000000, size: 0 file: 0, size: 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 http write filter: l:1 f:0 s:488
2018/02/17 12:46:28 [debug] 15406#15406: *219 http write filter limit 0
2018/02/17 12:46:28 [debug] 15406#15406: *219 posix_memalign: 000055F8B8563230:512 @16
2018/02/17 12:46:28 [debug] 15406#15406: *219 malloc: 000055F8B85ECAD0:16384
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL buf copy: 173
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL buf copy: 315
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL to write: 488
2018/02/17 12:46:28 [debug] 15406#15406: *219 SSL_write: 488
2018/02/17 12:46:28 [debug] 15406#15406: *219 http write filter 0000000000000000
2018/02/17 12:46:28 [debug] 15406#15406: *219 http copy filter: 0 "/?"
2018/02/17 12:46:28 [debug] 15406#15406: *219 http finalize request: 0, "/?" a:1, c:1
2018/02/17 12:46:28 [debug] 15406#15406: *219 set http keepalive handler

0
 
Georges OrwellSystem AdministratorAuthor Commented:
Thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.