Nginx and Websphere

Hi all!

I’m new in NGINX but I have try everything with very bad results. My
scenario is:

NGINX balancing over 2 servers using ip_hash. This servers runs
Websphere
and in every Websphere runs several apps.

Servers separately runs:

wasint-1.domain.com:9080/WebApp
wasint-2 domain.com:9080/WebApp

My configuration:

upstream webint {
ip_hash;
server wasint-1.domain.com:9080;
server wasint-2.domain.com:9080;
}

server {

    listen 80;
    server_name web.domain.com;


    location / {
            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 http://webint/WebApp;
}

}

All seems to be ok, but when I type in the web browser
http://web.domain.com
doesn´t work.

Posted at Nginx Forum:

On Tue, May 26, 2015 at 06:36:35AM -0400, sampy wrote:

Hi there,

upstream webint {

All seems to be ok, but when I type in the web browser http://web.domain.com
doesnt work.

What does “doesn’t work” mean?

What response do you get?

What response did you want to get instead?

What response do you get if you do

curl -H Host:web.domain.com -i http://wasint-1.domain.com:9080/WebApp

from the nginx server?

Does that match one of the previous two answers?

f

Francis D. [email protected]

Hi Francis,

What does “doesn’t work” mean?

web browser don’t show the web and appears the error “webint don’t
exists
in DNS”, but query arrives to the balanced server

What response do you get?

“webint don’t exists in DNS” but as I know “webint” is only a variable
or a
name for the upstream

What response did you want to get instead?

Oviously the web

What response do you get if you do

curl -H Host:web.domain.com -i http://wasint-1.domain.com:9080/WebApp

from the nginx server?

HTTP/1.1 302 Found

X-Powered-By: Servlet/3.0
Location: http://web.domain.com:9080/WebApp/
Content-Language: es-ES
Content-Length: 0

Does that match one of the previous two answers?

Yes, but don’t. Let me explain. It appears that the proxy_pass works,
because adds the port and /WebApp, but don’t show the web that is served
in
the host.

Regards

Posted at Nginx Forum:

Hi,

Francis D. Wrote:

You see “webint”, but you include “proxy_set_header Host $host;” in
your config?

That is unexpected to me.

Could you show the response to

curl -i http://web.domain.com/

I just remove “proxy_set_header Host $host”

And the result for curl:

HTTP/1.1 302 Found
Server: nginx/1.8.0
Date: Thu, 28 May 2015 06:27:41 GMT
Content-Type: text/html
Content-Length: 0
Connection: keep-alive
X-Powered-By: Servlet/3.0
Location: http://webint:9080/WebApp/main.jsf
Content-Language: es-ES
Set-Cookie: JSESSIONID=0000EOXejCoK14218Xm2cCtzxdd:-1; Path=/; HttpOnly
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache=“set-cookie, set-cookie2”

(Assume that I don’t know anything about WebSphere.)

X-Powered-By: Servlet/3.0
Module ngx_http_proxy_module may be useful. (Or just removing the
One request gets one response.
show whether or not that is useful.)
nginx Info Page
Posted at Nginx Forum:
Re: Nginx and Websphere

On Wed, May 27, 2015 at 07:27:25AM -0400, sampy wrote:

Hi there,

What does “doesn’t work” mean?

web browser don’t show the web and appears the error “webint don’t exists
in DNS”, but query arrives to the balanced server

You see “webint”, but you include “proxy_set_header Host $host;” in
your config?

That is unexpected to me.

Could you show the response to

curl -i http://web.domain.com/

from your client machine? Perhaps there is more than one redirection
happening.

What response did you want to get instead?

Oviously the web

What http response? A 301 redirect to a different url; or a 200 with
some specific content?

(Assume that I don’t know anything about WebSphere.)

Content-Language: es-ES
Content-Length: 0

Ok - after you show the response from the new curl command above –
the one that you make of your nginx server directly – it might become
clear whether that Location: header is being modified, or what it should
be modified to be.

Module ngx_http_proxy_module may be useful. (Or just removing the
“proxy_set_header Host $host;”.)

Does that match one of the previous two answers?

Yes, but don’t. Let me explain. It appears that the proxy_pass works,
because adds the port and /WebApp, but don’t show the web that is served in
the host.

One request gets one response.

Take the requests one at a time, and the path to the desired end state
may become clear.

(For example: I suspect that you may want to change the proxy_pass to be
just to “http://webint”, and you may want an extra “location=/{return
301
/WebApp/;}”, but the response from the first few requests will probably
show whether or not that is useful.)

Cheers,

f

Francis D. [email protected]

On Thu, May 28, 2015 at 02:35:10AM -0400, sampy wrote:

Francis D. Wrote:

Hi there,

Could you show the response to

curl -i http://web.domain.com/

I just remove “proxy_set_header Host $host”

And the result for curl:

HTTP/1.1 302 Found

Location: http://webint:9080/WebApp/main.jsf

Use “proxy_redirect” to tell nginx to convert the start of that back to
what you want it to be.

Possibly

proxy_redirect http://webint:9080/ /;

or possibly

proxy_redirect http://webint:9080/WebApp/ /;

depending on what your full plan is.

Then repeat the “curl” and see what is different.

And see if it works from your normal browser.

f

Francis D. [email protected]

On Thu, May 28, 2015 at 04:15:08AM -0400, sampy wrote:

Hi there,

I changed both possibilities and the “curl” shows the default web of nginx.

I’m not sure what state things are in now.

Can you copy-paste your current config, plus your curl requests and
responses?

curl -i http://web.domain.com/
curl -i http://web.domain.com/WebApp/

Thanks,

f

Francis D. [email protected]

Francis D. Wrote:

Possibly

And see if it works from your normal browser.

f

Francis D. [email protected]


nginx mailing list
[email protected]
nginx Info Page

I changed both possibilities and the “curl” shows the default web of
nginx.

regards

Posted at Nginx Forum:

On Thu, May 28, 2015 at 11:50:30AM -0400, sampy wrote:

Francis D. Wrote:

Hi there,

upstream webint {
ip_hash;
server wasint-1.carreras.sa;

Just to confirm: no “:9080” on that one? It probably means that a second
proxy_redirect will be needed; added below.

            #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_redirect http://webint/WebApp /;
proxy_redirect http://webint /;

There is no “proxy_pass” here, so the rest of the configuration is
effectively unused and the request is served from the filesystem –
which explains the responses you get.

Perhaps try instead

location / {
proxy_pass http://webint;
proxy_redirect http://webint/ /;
proxy_redirect http://webint:9080/ /;
}

and add the other bits if they are needed.

curl -i http://web.domain.com/
result: default nginx web

That should become “whatever the webapp returns for a / request”. If it
is not a redirect to /WebApp/, it can be fixed later.

curl -i http://web.domain.com/WebApp/
result:

That should become a sensible response – hopefully a redirect to
http://web.domain.com/WebApp/main.jsf.

If you do get that, they you can try

curl -i http://web.domain.com/WebApp/main.jsf

to see what happens next; or just try it in your normal browser.

f

Francis D. [email protected]

Why redirect instead of a proxy_pass?


Payam C.
Network Engineer / Security Specialist

Francis D. Wrote:

On Thu, May 28, 2015 at 04:15:08AM -0400, sampy wrote:

Hi there,

I changed both possibilities and the “curl” shows the default web of
nginx.

I’m not sure what state things are in now.

Can you copy-paste your current config, plus your curl requests and

upstream webint {
ip_hash;
server wasint-1.carreras.sa;
server wasint-2.carreras.sa:9080;
}

server {

    listen 80;
    server_name web.domain.com;


    location / {
            #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_redirect http://webint/WebApp /;
proxy_redirect http://webint /;
}

}

responses?

curl -i http://web.domain.com/
result: default nginx web
curl -i http://web.domain.com/WebApp/
result:
HTTP/1.1 404 Not Found
Server: nginx/1.8.0
Date: Thu, 28 May 2015 15:50:30 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive

404 Not Found

404 Not Found


nginx/1.8.0

Thanks

nginx Info Page
Posted at Nginx Forum:
Re: Nginx and Websphere

Hi there!

Now it’s near to work!

With this configuration:

upstream webint {
#ip_hash;
server wasint-1.domain.com:9080;
server wasint-2.domain.com:9080;
}

server {

    listen 80;
    server_name web.domain.com;

    location /WebApp {
            #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 http://webint;
proxy_redirect http://webint/ /;
proxy_redirect http://webint:9080/ /;
}

}

executing “curl -i http://web.domain.com/WebApp/main.js

Shows the web!!

And y a normal browser typing all the url
http://web.domain.com/WebApp/main.jsf” shows the correct web!! awesome!

Now I want to modify the base of this configuration to type only
http://web.domain.com and redirect to the web I want.

Thanks for all!!! I can feel that we are near to resolve that :slight_smile:

Francis D. Wrote:

second

which explains the responses you get.

That should become a sensible response – hopefully a redirect to
Francis D. [email protected]


nginx mailing list
[email protected]
nginx Info Page

Posted at Nginx Forum:

On Fri, May 29, 2015 at 02:01:00AM -0400, sampy wrote:

Hi there,

Now it’s near to work!

Good news.

    listen 80;
    }

You probably do not need “proxy_redirect http://webint/ /;”, because
what the upstream sends back probably always includes the :9080. But it
does no extra harm to leave it there.

executing “curl -i http://web.domain.com/WebApp/main.js

Shows the web!!

And y a normal browser typing all the url
http://web.domain.com/WebApp/main.jsf” shows the correct web!! awesome!

Now I want to modify the base of this configuration to type only
http://web.domain.com and redirect to the web I want.

Add an extra location block for that request:

location = / { return 301 /WebApp/; }

And then issue the “curl” command for the url you want; when you get a
301 redirect, issuer a curl command for the Location: header returned.

If the Location: header looks wrong – does not point at something in
web.domain.com – then you’ll have identified which request leads to
the unwanted response.

Good luck with it,

f

Francis D. [email protected]

Francis D. Wrote:

upstream webint {
location /WebApp {
what the upstream sends back probably always includes the :9080. But

If the Location: header looks wrong – does not point at something in
nginx mailing list
[email protected]
nginx Info Page

hi there.

I’m happy because with web.domain.com/WebApp works fine.

But when I change LOCATION from:

location /WebApp {
upstream balancer {
server server1.domain.com:9080;
server server2.domain.com:9080;
}

location /WebApp {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_pass http://balancer/WebApp;
proxy_redirect http://balancer:9080/ /;
}
}

}

to:
upstream balancer {
server server1.domain.com:9080;
server server2.domain.com:9080;
}

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_pass http://balancer/WebApp;
proxy_redirect http://balancer:9080/ /;
}

}

stop working. “curl” sees the 302 redirection in both cases, but the web
is
not showed in the second case. I think I forget something or I have some
mistake in syntax.

Regards

Posted at Nginx Forum:

unclepieman Wrote:

Why redirect instead of a proxy_pass?

Yes, you’re right. Now with proxy_pass works with some minor errors

On Thu, May 28, 2015 at 04:15:08AM -0400, sampy wrote:
and
server_name web.domain.com;

HTTP/1.1 404 Not Found


nginx/1.8.0 > _______________________________________________

nginx Info Page
Posted at Nginx Forum:
Re: Nginx and Websphere

On Fri, May 29, 2015 at 12:51:51PM -0400, sampy wrote:

Francis D. Wrote:

    location /WebApp {
            proxy_pass http://webint;
            proxy_redirect http://webint:9080/ /;
    }

But when I change LOCATION from:

location /WebApp {
proxy_pass http://balancer/WebApp;
proxy_redirect http://balancer:9080/ /;
}

to:

location / {
proxy_pass http://balancer/WebApp;
proxy_redirect http://balancer:9080/ /;
}

stop working. “curl” sees the 302 redirection in both cases, but the web is
not showed in the second case. I think I forget something or I have some
mistake in syntax.

Look at the proxy_pass in the very first one, the one that worked.

It is just http://webint – no / or anything after it.

Whether you use “location /” or “location /WebApp”, just use
“proxy_pass http://balancer;”

Module ngx_http_proxy_module for the details.

f

Francis D. [email protected]

Hi Francis,

We have been nginx with Php fpm for the last one year. In the last 2
months
we have been seeing php fpm getting overloaded sometimes and eventually
leading to 502/500/504 errors returned by nginx. Could you please help
us
out?

Let me what details you would need I would send them in the next mail.

Thank you.