Proxy_pass & getServerPort problems

When I use the nginx upstream and proxy_pass to Reverse Proxy the
request. the configuration is:

upstream w3new_cls {
server szxap205-in.huawei.com:9090;
server szxap206-in.huawei.com:9090;
}

server {
listen 80;
server_name w3.huawei.com;

location /NetWeb/ {
proxy_pass http://w3new_cls/NetWeb/;
proxy_redirect off;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

when I access the URL: http://w3.huawei.com/NetWeb and the application
use the <%request.getServerPort%> to get the server port is 9090, Not
the port 80.
But I want to get the port is w3.huawei.com:80, How can I to resovle the
problems.
Thanks for Help.

On Wed, Feb 12, 2014 at 08:51:13AM +0100, Jiang Web wrote:

Hi there,

location /NetWeb/ {
proxy_pass http://w3new_cls/NetWeb/;
proxy_redirect off;
proxy_set_header Host $host:80;

when I access the URL: http://w3.huawei.com/NetWeb and the application
use the <%request.getServerPort%> to get the server port is 9090, Not
the port 80.
But I want to get the port is w3.huawei.com:80, How can I to resovle the
problems.

getServerPort is not an nginx thing, and nginx probably cannot affect
what it reports.

What do you do with the result of getServerPort?

Would using something like getHeader(“Host”) be adequate instead?

f

Francis D. [email protected]

Francis D. wrote in post #1136476:

On Wed, Feb 12, 2014 at 08:51:13AM +0100, Jiang Web wrote:

Hi there,

location /NetWeb/ {
proxy_pass http://w3new_cls/NetWeb/;
proxy_redirect off;
proxy_set_header Host $host:80;

when I access the URL: http://w3.huawei.com/NetWeb and the application
use the <%request.getServerPort%> to get the server port is 9090, Not
the port 80.
But I want to get the port is w3.huawei.com:80, How can I to resovle the
problems.

getServerPort is not an nginx thing, and nginx probably cannot affect
what it reports.

What do you do with the result of getServerPort?

Would using something like getHeader(“Host”) be adequate instead?

f

Francis D. [email protected]

When I access the application http://w3.huawei.com/NetWeb. the
application will 302(relocation) to
https://login.huawei.com/login?redirect=xxxxxxxxx to make the user login
the system(the http://login.huawei.com/login is our sso system). The
xxxxxxx in the URI is the last request url(we think is
http://w3.huawei.com/NetWeb), and we get the last request url(in java
program) using <%request.getRequestURL%>, but the result is
xxxxxxxx=http://w3.huawei.com:9090/NetWeb not the
http://w3.huawei.com/NetWeb. We test it and found that:
<%request.getServerName%> is w3.huawei.com
<%request.getServerPort%> is 9090
<%request.getURI%> is /NetWeb
so we think that when we use the nginx as a reverse proxy to proxy the
request, the request.getServerPort is 9090 not 80. If we use the apache
as a reverse proxy to proxy the request adding parameter
“ProxyPreserveHost on”, the request.getServerPort is 80.

Thanks for help and reply.

On Thu, Feb 13, 2014 at 02:00:48AM +0100, Jiang Web wrote:

Francis D. wrote in post #1136476:

Hi there,

getServerPort is not an nginx thing, and nginx probably cannot affect
what it reports.

What do you do with the result of getServerPort?

“ProxyPreserveHost on”, the request.getServerPort is 80.
The nginx equivalent to “ProxyPreserveHost on” is probably
“proxy_set_header Host $http_host”. It might be worth trying that.

If that doesn’t work, then perhaps tcpdump the traffic between apache
and the backend when it works, and between nginx and the backend when
it fails, and spot the difference.

The relevant question is probably: what does your java getServerPort
(or getRequestURL) do to find its answer? Once you know that, you can
see whether it is possible for nginx to influence it. (Since apache did
influence it, presumably nginx can too.)

f

Francis D. [email protected]