# Making Tomcat accessible only through nginx reverse proxy

**URL:** <https://www.ruby-forum.com/t/making-tomcat-accessible-only-through-nginx-reverse-proxy/244490>\
**Category:** NGINX\
**Created:** [April 20, 2016, 1:20pm UTC](https://www.ruby-forum.com/t/making-tomcat-accessible-only-through-nginx-reverse-proxy/244490 "2016-04-20T13:20:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [April 20, 2016, 1:20pm UTC](https://www.ruby-forum.com/t/making-tomcat-accessible-only-through-nginx-reverse-proxy/244490/1 "2016-04-20T13:20:09Z")

</div>

I have a Tomcat server serving a web application and I have a Nginx  
server  
running in front of it as a reverse proxy. Both the servers are on  
Intranet,  
in the same domain network. The issue I am facing is, the tomcat server  
is  
accessible through both IP addresses - if I use the Nginx IP, it  
redirects  
to the Tomcat FQDN (expected) but if I ping using the FQDN  
[tomcat.domain.com](http://tomcat.domain.com), it reveals the real IP of the Tomcat server and not  
that  
of Nginx server. Effectively, my Nginx server is not serving any  
purpose. I  
was suggested to firewall the Tomcat instance, but based on my findings  
from  
different forums, limiting Tomcat to listen to localhost seemed to be  
the  
way to go. In order to prevent Tomcat from listening to other IPs, I  
added  
“address=127.0.0.1” to the connector configuration. The entire connector  
block is like this -

\<Connector port=“8080”  
address=“127.0.0.1”  
maxThreads=“150”  
minSpareThreads=“25”  
connectionTimeout=“20000”  
enableLookups=“false”  
maxHttpHeaderSize=“8192”  
protocol=“HTTP/1.1”  
useBodyEncodingForURI=“true”  
redirectPort=“8443”  
acceptCount=“100”  
disableUploadTimeout=“true”  
proxyName=  
proxyPort=“80”/\>

In the Nginx server, I have these lines for the server configuration.

server {  
listen 80 default\_server;  
listen [::]:80 default\_server ipv6only=on;

```
    server_name <FQDN>;
    location / {
    proxy_pass <FQDN>;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;

```

}  
}  
Now, if I try to use the FQDN to access the web application, Chrome  
reports  
ERR\_CONNECTION\_REFUSED. My Nginx configuration seems to be the culprit  
based  
on what I understood. How can it be corrected?

Posted at Nginx Forum:

> **[Making Tomcat accessible only through nginx reverse proxy](https://forum.nginx.org/read.php?2,266297,266297#msg-266297)**
>
> I have a Tomcat server serving a web application and I have a Nginx server running in front of it as a reverse proxy. Both the servers are on Intranet, in the same domain network. The issue I am facing is, the tomcat server is accessible through both...

---

<div class="post-metadata">

**Author:** ![gischethans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gischethans](https://www.ruby-forum.com/u/gischethans)\
**Post date:** [April 20, 2016, 8:18pm UTC](https://www.ruby-forum.com/t/making-tomcat-accessible-only-through-nginx-reverse-proxy/244490/2 "2016-04-20T20:18:25Z")

</div>

On Wed, Apr 20, 2016 at 07:19:55AM -0400, gischethans wrote:

Hi there,

> I have a Tomcat server serving a web application and I have a Nginx server  
> running in front of it as a reverse proxy.

What you need is that your users talk to nginx, and that nginx is able  
to talk to tomcat.

What you additionally want, is that your users do not talk to tomcat.

All of that network setup is outside of anything that nginx can do.

> In order to prevent Tomcat from listening to other IPs, I added  
> “address=127.0.0.1” to the connector configuration.

That will mean that your users cannot talk to tomcat (unless you do  
something special to allow them to).

It will also mean that nginx cannot talk to tomcat, unless you do  
something special to allow it to.

The easiest special thing is probably to run nginx on the same server  
as tomcat.

If that is not what you want, then you will probably need some  
firewalling  
/ ip forwarding on the tomcat machine to allow nginx connect to  
something  
which gets sent to tomcat.

(But at that point, it may be easier to just leave tomcat listening on  
the public address, and add firewalling to block anything other than  
nginx from accessing it.)

> In the Nginx server, I have these lines for the server configuration.

On the nginx side, what you have looks fine. In the “proxy\_pass” line,  
it  
will probably be simpler if you use the IP:port that tomcat is listening  
on (that nginx can connect to) rather than the hostname.

> Now, if I try to use the FQDN to access the web application, Chrome reports  
> ERR\_CONNECTION\_REFUSED. My Nginx configuration seems to be the culprit based  
> on what I understood. How can it be corrected?

I suspect that your request to the FQDN does not get to nginx. After  
you have things configured correctly, changing name resolution (dns)  
so that the FQDN corresponds to the nginx IP address instead of the  
tomcat IP address will be a necessary step.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![gischethans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gischethans](https://www.ruby-forum.com/u/gischethans)\
**Post date:** [April 26, 2016, 4:07am UTC](https://www.ruby-forum.com/t/making-tomcat-accessible-only-through-nginx-reverse-proxy/244490/3 "2016-04-26T04:07:54Z")

</div>

please check your proxy\_pass parameter, it should point to your tomcat  
endpoint:

> **[Nginx + Apache Tomcat configuration example - Mkyong.com](https://mkyong.com/nginx/nginx-apache-tomcat-configuration-example/)**
>
> \- Nginx + Apache Tomcat configuration example

hope this helps.

On Wed, Apr 20, 2016 at 7:19 PM, gischethans  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
