Avatar of Jason Yu
Jason Yu
Flag for United States of America asked on

How to set up nginx server to proxy to a java application

I have a nginx server sitting on dmz to poing traffic to a java application.  The reason why i call it java application is because it only has a xxx.jar file running. I could like to proxy the http traffic to the java application. The port is poart 80. I did the following nginx configuration as below, but it doesn't work. Is there any nginx experts here can help me with this issue?


[root@pmsdev jyu]# ps -ef | grep java
root      3108     1  0 13:29 ?        00:01:56 java -Dspring.profiles.active=dev -jar /data/AveryRollProduction.jar /tmp
root      3933  3918  0 17:24 pts/0    00:00:00 grep --color=auto java



    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        # server_name  localhost;
        # root         /usr/share/nginx/html;

        server_name  localhost;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {

        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;
        proxy_pass http://10.104.0.104:80;



        }

Open in new window

LinuxWeb ServersApache Web ServerHTTP Protocol

Avatar of undefined
Last Comment
Jason Yu

8/22/2022 - Mon
David Johnson, CD

you need to be running a web server that has the .jar file running at all times.  A jar file by itself is simply a file that contains instructions for use by java
noci

And the Java application is listening on port 80?

you can verify the listening port by using
netstat -antp  

on the server where the java application is active....
(there is a <pid>/java at the end of the line)

And then stop this server and use netstat -antp again to verfy the ports used.
And if listening on port 80, and using http you should be able to verify it's working by using a browser to that addresses.
ASKER CERTIFIED SOLUTION
Jason Yu

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jason Yu

ASKER
I commented out the root line and add a new one.

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        # server_name  localhost;
        # root         /usr/share/nginx/html;

        server_name  localhost;
        #root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        proxy_pass http://10.104.0.104:80;
        }

        # redirect server error pages to the static page /40x.html
        #
        error_page 404 /404.html;
            location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Jason Yu

ASKER
I found the solution.