Solved

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

Posted on 2016-08-16
5
20 Views
Last Modified: 2016-08-22
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

0
Comment
Question by:Jason Yu
  • 3
5 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
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
0
 
LVL 39

Expert Comment

by:noci
Comment Utility
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.
0
 

Accepted Solution

by:
Jason Yu earned 0 total points
Comment Utility
Thanks guys, I got it resoled by set up reverse proxy.
0
 

Author Comment

by:Jason Yu
Comment Utility
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 {
0
 

Author Closing Comment

by:Jason Yu
Comment Utility
I found the solution.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now