Is it possible to run Java web application using Nginx server only without tomcat server?
Asked Answered
R

4

6

Is it possible to run Java web application using Nginx server only without tomcat server ?

Rexanna answered 25/2, 2019 at 6:59 Comment(1)
Maybe use Jetty?Indeterminism
C
6

I guess it's not possible since Nginx is not a servlet container.

A servlet container is an application server that implements some version of the Java Servlet Specification.

And this is not the case of Nginx.

Conciliate answered 25/2, 2019 at 7:5 Comment(0)
A
5

nginx has no understanding of what a .war file is as it is not a servlet container. So, answer to your question is No! it is not possible. However, you can configure nginx to act as a reverse proxy in front of a Tomcat server.

Also, this link may help you in details about nginx

Asdic answered 25/2, 2019 at 7:43 Comment(0)
F
2

Nowadays frameworks such as Spring come with embedded application servers. Spring use Tomcat by default as application server and we don't have to worry about it.

Now, to answer your question, when you say webapplication, it can mean three things,

  1. Just Frontend (to serve static files / html,js,css)
  2. Just Backend (May be Rest API's etc where your users can hit api's using Postman, curl etc.. or may be just a tier-2 backend server to serve tier-1 backend server)
  3. Frontend(static/dynamic content) + Backend

I Suppose you meant 3,

Now we are in System design,

Case 1: If you have your UI content as pure static (html, js, css)

a) Front end code directly written in html, js, css

b) Front end code written in React, Angular, they provide compilers/builds to convert the React/Angular understandable code to just pure static html, js, css. Take the build and keep handy,

Approach 1: Bundle the build together as jar (as part of your spring jar) and serve both backend and frontend using the embedded application server.

Approach 2 Run a proxy webserver (I meant webserver! here not application server) in front (nginx or apacheHTTP server may be) and route traffic between frontend and backend spring application server.

Note: All you need to let webservers (via conf files) know is the location of your html files (which internally have access to js/css code) to route traffic to frontend. But for backend, it already runs in Tomcat application server (servlet container).

Case 2: If you have your UI content are not pure static (html, js, css)

Approach 1: If you are using JSP, thymeleaf, then bundle them together as jar and serve via application server only. Because JSP, thymeleaf prepares html,js,css dynamically (using your api request, java models etc..). You cannot serve frontend like a raw static content here directly using webservers.

Flemings answered 6/8, 2022 at 6:11 Comment(0)
D
1

If you only use static files and restful services (access by javascript framework) you can try Nginx-Clojure and its sub-project Nginx-Jersey.

If you use servlet/jsp based web application you can try Nginx-Clojure and its sub-project Nginx-Tomcat8 which does not use tomcat as a server but only a servlet package and does use Nginx as the HTTP server.

Dysplasia answered 25/11, 2019 at 15:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.