Solved

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

Posted on 2016-08-16
5
24 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
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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINUX, CPANEL & WHM 5 44
Error installing extension Linux 4 58
Why Xampp showing MySQL as Maria DB on Welcome Page ? 8 42
More Than One Website On Same DMZ Server 3 47
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
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.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

943 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

4 Experts available now in Live!

Get 1:1 Help Now