Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect nginx to my java module

I am a really beginner on this topic, I need some helpful articles and your guidance. I want to build RESTFul API web service. As a http server chosen nginx. But I don't know (couldnt find any article) anything about how I can redirect my query to my java module, which handles request and gives back in JSON to nginx. If my thoughts on type of back-end is not correct please help me to figure out on this...

like image 578
user1318496 Avatar asked Dec 21 '22 11:12

user1318496


1 Answers

You will need to build your Java service in its own app server -- Tomcat would be a good choice for this. From there, it's a simple matter of configuring nginx to act as a proxy to Tomcat. Your nginx configuration will look something like the following:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 4096;
    # multi_accept on;
}

http {

    server {
        listen 80; #incoming port for nginx
        server_name localhost;
        location / {
            proxy_pass http://127.0.0.1:8080;
        }
    }

#...and other things, like basic settings, logging, mail, etc. 

The important piece here is the setting for proxy_pass. That's telling nginx to accept requests on port 80 and redirect them to port 8080 (Tomcat's standard port).

like image 100
rtperson Avatar answered Dec 29 '22 14:12

rtperson