Welcome! Log In Create A New Profile

Advanced

502 Bad Gateway errors from Nginx when trying to access Tomcat

April 22, 2016 02:29AM
I have JIRA and Nginx running on the same server with Nginx installed to serve as a reverse proxy. From what I learnt from various sources, in the Tomcat server.xml file, I must add an address="127.0.0.1" attribute so that Tomcat does not listen to outside IPs. But once I add that to my 8080 and 8443 connectors, things stop working i.e., the JIRA site becomes inaccessible. Browser displays Connection refused / connection timed out errors. Trying to access the site through curl gives me 502 Bad gateway error. I have also checked the Nginx error log which shows this -

connect() failed (111: Connection refused) while connecting to upstream, client: <IP Address>, server: <FQDN>, request: "GET / HTTP/1.1", upstream: "http://<IP>:8080/", host: <FQDN>

Here is my nginx.conf
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

and the entire content of the file for sites-enabled

server {
listen 80;


server_name test-pcrdesk.ingrnet.com;
location / {

proxy_pass http://<IP>:8080/; #Here I have tried the real IP of the server, localhost, FQDN with and without port 8080, almost anything I could think of
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;


}
}

Here is server.xml file configuration for Tomcat.
<Connector port="8080"
address="127.0.0.1"
maxThreads="150"
minSpareThreads="25"
connectionTimeout="20000"
enableLookups="false"
maxHttpHeaderSize="8192"
protocol="HTTP/1.1"
useBodyEncodingForURI="true"
acceptCount="100"
redirectPort="8443"
disableUploadTimeout="true"
proxyName=<FQDN>
proxyPort="80"/>

<Connector port="8443"
address="127.0.0.1"
SSLEnabled="true"
acceptCount="100"
clientAuth="false"
connectionTimeout="20000"
disableUploadTimeout="true"
enableLookups="false"
keyAlias=<value>
keystoreFile=<jks file>
keystorePass=<password>
keystoreType="JKS"
maxHttpHeaderSize="8192"
maxSpareThreads="75"
maxThreads="150"
minSpareThreads="25"
protocol="org.apache.coyote.http11.Http11Protocol"
scheme="https"
secure="true"
sslProtocol="TLS"
useBodyEncodingForURI="true"/>

What is wrong with my configuration?
Subject Author Posted

502 Bad Gateway errors from Nginx when trying to access Tomcat

gischethans April 22, 2016 02:29AM

Re: 502 Bad Gateway errors from Nginx when trying to access Tomcat

mex April 22, 2016 02:49AM

Re: 502 Bad Gateway errors from Nginx when trying to access Tomcat

gischethans April 22, 2016 03:21AM

Re: 502 Bad Gateway errors from Nginx when trying to access Tomcat

Francis Daly April 23, 2016 03:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 301
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready