# Newbie: Proxy to Glassfish

**URL:** <https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567>\
**Category:** NGINX\
**Created:** [April 8, 2011, 9:26pm UTC](https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567 "2011-04-08T21:26:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 8, 2011, 9:26pm UTC](https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567/1 "2011-04-08T21:26:25Z")

</div>

Hello,  
I’m migrating an app from Apache/JBoss to nginx/Glassfish. I think I’m  
starting to grasp the server-location design but am getting errors when  
I try to proxy a request to Glassfish. Here’s a clip from my config:

server {  
server\_name [www.foobar.com](http://www.foobar.com) [foobar.com](http://foobar.com);  
root html/prod;  
index index.html;  
location /dc {  
proxy\_pass $scheme://localhost:8080$request\_uri;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
}  
}

The gist of it is I want all dynamic content (dc) to go to glassfish,  
i.e. [foobar.com/dc/somepath/page.jsp](http://foobar.com/dc/somepath/page.jsp)  
Everything else (presumably the static content) is served from  
html/prod. (That part works)  
I want the path to determine what happens, not the file extensions  
(because I have some .js that is static and other that is generated by  
the server).

I have a “hello world” app running on glassfish that works when accessed  
directly from localhost:8080/webtest/home,  
but when I try [foobar.com/dc/webtest/home](http://foobar.com/dc/webtest/home) I get a 502 Bad Gateway error  
in the browser. The nginx error log reports this:

2011/04/08 14:13:30 [notice] 3884#3940: signal process started  
2011/04/08 14:13:35 [error] 828#3472: \*6 no resolver defined to resolve  
localhost, client: 127.0.0.1, server: [www.foobar.com](http://www.foobar.com), request: “GET  
/dc/webtest/home HTTP/1.1”, host: “[foobar.com](http://foobar.com)”

Any ideas what might be wrong with my configuration?  
Thanks!  
Greg

Posted at Nginx Forum:

> **[Newbie: Proxy to Glassfish](https://forum.nginx.org/read.php?2,189502,189502#msg-189502)**
>
> Hello, I'm migrating an app from Apache/JBoss to nginx/Glassfish. I think I'm starting to grasp the server-location design but am getting errors when I try to proxy a request to Glassfish. Here's a clip from my config: server { server\_name...

---

<div class="post-metadata">

**Author:** ![GZ1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@GZ1](https://www.ruby-forum.com/u/GZ1)\
**Post date:** [April 8, 2011, 10:47pm UTC](https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567/2 "2011-04-08T22:47:13Z")

</div>

Hello!

On Fri, Apr 08, 2011 at 03:25:53PM -0400, GZ1 wrote:

> ```
> proxy_pass $scheme://localhost:8080$request_uri;
> 
> ```

- 

```
  proxy_pass $scheme://localhost:8080$request_uri;

```

- 

```
  proxy_pass http://localhost:8080;

```

> I want the path to determine what happens, not the file extensions  
> localhost, client: 127.0.0.1, server: [www.foobar.com](http://www.foobar.com), request: “GET  
> /dc/webtest/home HTTP/1.1”, host: “[foobar.com](http://foobar.com)”
> 
> Any ideas what might be wrong with my configuration?

Don’t use variables in proxy\_pass directive unless you really know  
why you need them and what it implies.

Maxim D.

---

<div class="post-metadata">

**Author:** ![GZ1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@GZ1](https://www.ruby-forum.com/u/GZ1)\
**Post date:** [April 8, 2011, 11:18pm UTC](https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567/3 "2011-04-08T23:18:07Z")

</div>

> Don’t use variables in proxy\_pass directive unless you really know  
> why you need them and what it implies.

Ok, I changed that line to this:

```
  proxy_pass localhost:8080;

```

Still getting the same error unfortunately.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,189502,189552#msg-189552](http://forum.nginx.org/read.php?2,189502,189552#msg-189552)

---

<div class="post-metadata">

**Author:** ![GZ1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@GZ1](https://www.ruby-forum.com/u/GZ1)\
**Post date:** [April 9, 2011, 11:01am UTC](https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567/4 "2011-04-09T11:01:28Z")

</div>

On Sat, Apr 9, 2011 at 4:55 AM, GZ1 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> One question, though… this didn’t work:
> 
> proxy\_pass localhost:8080;
> 
> This did:
> 
> proxy\_pass [http://localhost:8080](http://localhost:8080);

Because the http:// is required.

> What if I want to proxy my ssl too?

I believe it is not recommended to proxy to ssl backend (if possible at  
all).

---

<div class="post-metadata">

**Author:** ![GZ1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@GZ1](https://www.ruby-forum.com/u/GZ1)\
**Post date:** [April 8, 2011, 11:56pm UTC](https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567/5 "2011-04-08T23:56:19Z")

</div>

Making progress! The /dc location wasn’t working because it wasn’t just  
rewriting the url, just proxying, so on my Glassfish server it was  
looking for /dc/…, which wasn’t there.

So for now I’ll just use location / and figure out another way to  
differentiate the dynamic and static content by location.  
At least now I can reach Glassfish from nginx, which is pretty cool.

Thanks for the lead!

One question, though… this didn’t work:

proxy\_pass localhost:8080;

This did:

proxy\_pass [http://localhost:8080](http://localhost:8080);

What if I want to proxy my ssl too?

Posted at Nginx Forum:

> **[Re: Newbie: Proxy to Glassfish](https://forum.nginx.org/read.php?2,189502,189565#msg-189565)**
>
> Hello, I'm migrating an app from Apache/JBoss to nginx/Glassfish. I think I'm starting to grasp the server-location design but am getting errors when I try to proxy a request to Glassfish. Here's a clip from my config: server { server\_name...

---

<div class="post-metadata">

**Author:** ![GZ1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@GZ1](https://www.ruby-forum.com/u/GZ1)\
**Post date:** [April 9, 2011, 7:26pm UTC](https://www.ruby-forum.com/t/newbie-proxy-to-glassfish/205567/6 "2011-04-09T19:26:58Z")

</div>

On Sat, 2011-04-09 at 16:00 +0700, Edho P Arief wrote:

> > What if I want to proxy my ssl too?
> 
> I believe it is not recommended to proxy to ssl backend (if possible at all).

You cannot “proxy SSL”, but you can setup a separate SSL connection to  
the backend.

Cliff
