Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-08-16
5
Medium Priority
?
281 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 84

Expert Comment

by:David Johnson, CD, MVP
ID: 41759760
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 40

Expert Comment

by:noci
ID: 41760194
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
ID: 41760277
Thanks guys, I got it resoled by set up reverse proxy.
0
 

Author Comment

by:Jason Yu
ID: 41760278
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
ID: 41765046
I found the solution.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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ā€¦
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

927 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