[英]Is it possible to run Java web application using Nginx server only without tomcat server?
Is it possible to run Java web application using Nginx server only without tomcat server?是否可以仅使用 Nginx 服务器运行 Java web 应用程序而没有 Z1B359D87540678B535BEFA04
I guess it's not possible since Nginx is not a servlet container.我想这是不可能的,因为 Nginx 不是 servlet 容器。
A servlet container is an application server that implements some version of the Java Servlet Specification.
servlet 容器是一个应用服务器,它实现了某个版本的 Java Servlet 规范。
And this is not the case of Nginx.而这不是 Nginx 的情况。
nginx
has no understanding of what a .war file is as it is not a servlet container. nginx
不了解 .war 文件是什么,因为它不是 servlet 容器。 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.但是,您可以将
nginx
配置为充当 Tomcat 服务器前的反向代理。
Also, this link may help you in details about nginx
此外,此链接可能会帮助您了解有关
nginx
详细信息
If you only use static files and restful services (access by javascript framework) you can try Nginx-Clojure and its sub-project Nginx-Jersey .如果你只使用静态文件和 restful 服务(通过 javascript 框架访问),你可以尝试Nginx-Clojure及其子项目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.如果您使用基于 servlet/jsp 的 Web 应用程序,您可以尝试Nginx-Clojure及其子项目Nginx-Tomcat8 ,它不使用 tomcat 作为服务器,而仅使用 servlet 包,并使用 Nginx 作为 HTTP 服务器。
Nowadays frameworks such as Spring come with embedded application servers.如今,Spring 等框架都带有嵌入式应用服务器。 Spring use Tomcat by default as application server and we don't have to worry about it.
Spring 默认使用 Tomcat 作为应用服务器,我们不必担心。
Now, to answer your question, when you say webapplication, it can mean three things,现在,回答你的问题,当你说 webapplication 时,它可能意味着三件事,
I Suppose you meant 3,我想你的意思是3,
Now we are in System design,现在我们在系统设计中,
Case 1: If you have your UI content as pure static (html, js, css)案例 1:如果您的 UI 内容为纯 static (html, js, css)
a) Front end code directly written in html, js, css a) 前端代码直接写在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. 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.方法 1:将构建捆绑在一起作为 jar(作为 spring jar 的一部分)并使用嵌入式应用程序服务器为后端和前端提供服务。
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.方法 2在前端(可能是 nginx 或 apacheHTTP 服务器)运行代理网络服务器(我的意思是网络服务器!这里不是应用程序服务器),并在前端和后端 spring 应用程序服务器之间路由流量。
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.注意:您需要让网络服务器(通过 conf 文件)知道 html 文件(内部可以访问 js/css 代码)的位置,以将流量路由到前端。 But for backend, it already runs in Tomcat application server (servlet container).
但是对于后端,它已经在 Tomcat 应用服务器(servlet 容器)中运行。
Case 2: If you have your UI content are not pure static (html, js, css)案例2:如果你的UI内容不是纯static(html,js,css)
Approach 1: If you are using JSP, thymeleaf, then bundle them together as jar and serve via application server only.方法 1:如果您使用 JSP、thymeleaf,则将它们捆绑在一起作为 jar 并仅通过应用程序服务器提供服务。 Because JSP, thymeleaf prepares html,js,css dynamically (using your api request, java models etc..).
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.
您不能直接使用网络服务器在此处提供像原始 static 内容这样的前端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.