简体   繁体   English

是否可以仅使用 Nginx 服务器运行 Java web 应用程序而不使用 Z1B359D87540678B535BEFA04

[英]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 时,它可能意味着三件事,

  1. Just Frontend (to serve static files / html,js,css)只是前端(服务 static 文件 / 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)只是后端(可能是 Rest API 等,您的用户可以使用 Postman、curl 等来访问 API
  3. Frontend(static/dynamic content) + Backend前端(静态/动态内容)+ 后端

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.

相关问题 Tomcat服务器上的Java Web应用程序部署 - java web application deployment on tomcat server 没有码头工人,是否可以使用gitlab-ci将简单的Java Web应用程序部署到本地服务器? - is it possible to deploy a simple java web application to a local server using gitlab-ci without docker? 是否可以使用 WildFly 在 Java 应用程序中运行 gRPC 服务器? - Is it possible to run a gRPC server in a Java application using WildFly? 是否可以在没有应用程序服务器的情况下运行Spring? - Is it possible to run Spring without an application server? 在部署简单的Web应用程序时,java文件(即servlet)不在服务器上运行(Tomcat) - While deploying a simple web application, the java file (i.e servlet) doesn't run on server (Tomcat) 如何在Apache Tomcat 6服务器中修复Java Spring MVC Web应用程序的运行时间? - How to fix java spring mvc web application run time in Apache Tomcat 6 server? 是否可以在tomcat中运行RMI服务器? - Is it possible to run RMI server in tomcat? 如何在不使用 tomcat 的情况下运行 jersey-server webservice 服务器 - How to run jersey-server webservice server without using tomcat 如何防止重新启动我的Web应用程序(不仅重新启动tomcat服务器)? - How to prevent restart my web application( not only restart the tomcat server)? 无需服务器应用程序即可部署Java Web服务 - Deploying java web service without server application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM