简体   繁体   English

Spring boot.jar to digital ocean droplet (Linux Ubuntu):Web 服务器启动失败。 80 端口已被使用

[英]Spring boot .jar to digital ocean droplet (Linux Ubuntu) :Web server failed to start. Port 80 was already in use

I have an Digitalocean Droplet (virtual private server) that has Ubuntu 18.04 running on it.我有一个运行 Ubuntu 18.04 的 Digitalocean Droplet(虚拟专用服务器)。 I installed Apache Web Server and have my website running on it.我安装了 Apache Web 服务器并在其上运行我的网站。 It's open to traffic on HTTP port 80. My virtual host is setup at /var/www/MyDomainNameHere/public_html/ and I do have a custom domain name pointing to the IP.它在 HTTP 端口 80 上对流量开放。我的虚拟主机设置在/var/www/MyDomainNameHere/public_html/并且我确实有一个指向 IP 的自定义域名。

I am trying to deploy/run a executable.jar that contains a Spring boot API.我正在尝试部署/运行一个可执行文件.jar,其中包含一个 Spring 启动 API。 It has some basic GET/POST/DELETE HTTP requests.它有一些基本的 GET/POST/DELETE HTTP 请求。 When I run the jar by当我运行 jar 时

java -jar rest-service.jar

I get this error message我收到此错误消息

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 80 was already in use.

Does this mean the Apache Web Server that is open to Traffic on port 80 on this Digital ocean droplet won't let me run the API jar on the same server (The JAR loads up an Apache Tomcat embedded server, I set it to port 80 based on research)? Does this mean the Apache Web Server that is open to Traffic on port 80 on this Digital ocean droplet won't let me run the API jar on the same server (The JAR loads up an Apache Tomcat embedded server, I set it to port 80基于研究)? Do I need to buy another droplet?我需要再买一个液滴吗? Or can I maybe change the port number for the spring boot jar to something other than port 80?或者我可以将 spring 引导 jar 的端口号更改为端口 80 以外的端口号吗? It's an API, so I need to be able to hit the end points这是一个 API,所以我需要能够达到终点

Yes, Apache Web Server using the port and you change your spring application 80 to any other port and use the reverse proxy in Apache Web server. Yes, Apache Web Server using the port and you change your spring application 80 to any other port and use the reverse proxy in Apache Web server. here is the link to configure the reverse proxy这是配置反向代理的链接

Apache as a Reverse Proxy with mod_proxy Apache 作为带有 mod_proxy 的反向代理

So I will answer my own question.所以我会回答我自己的问题。 I googled and searched stackoverflow but most people were using the reverse proxy to direct traffic to their standalone embedded Tomcat server (most of time a Spring Boot app) which wasn't applicable to my situation.我用谷歌搜索并搜索了 stackoverflow,但大多数人都使用反向代理将流量引导到他们独立的嵌入式 Tomcat 服务器(大部分时间是 Spring 引导应用程序),这不适用于我的情况。

However, I already had a static html website at alpizano.me hosted on Digital Ocean that I wanted to use as my Front-end, and only forward certain HTTP requests to my Spring Boot app, which was a REST API essentially. However, I already had a static html website at alpizano.me hosted on Digital Ocean that I wanted to use as my Front-end, and only forward certain HTTP requests to my Spring Boot app, which was a REST API essentially.

So after installing Java and PostgreSQL on my DigitalOcean droplet, I SCP'd my JAR file (running ./mvnw clean package -Dmaven.test.skip=true to create it) to my server to a directory like, /var/myapp. So after installing Java and PostgreSQL on my DigitalOcean droplet, I SCP'd my JAR file (running ./mvnw clean package -Dmaven.test.skip=true to create it) to my server to a directory like, /var/myapp.

Then after researching for a few days and trying multiple things, I was able to figure out the combination that would allow me to view my website when navigating to alpizano.me , but still allow me to hit my API endpoints that were running on my server as-well, after I ran my jar via java -jar myapp.jar然后在研究了几天并尝试了多种方法之后,我能够找出可以让我在导航到alpizano.me时查看我的网站的组合,但仍然允许我访问在我的服务器上运行的 API 端点同样,在我通过java -jar myapp.jar运行我的 jar 之后

So I basically had to set up my.conf file in the /etc/apache2/sites-available dir (I only used 1 virtual host for this project) as:所以我基本上必须在/etc/apache2/sites-available目录中设置 my.conf 文件(我只为这个项目使用了 1 个虚拟主机):

<VirtualHost *:80>
    ServerName yourservername.com
    DocumentRoot /var/www/yourservername.com/public_html

    ProxyPreserveHost On
    ProxyPass /api http://127.0.0.1:8080/
    ProxyPassReverse /api http://127.0.0.1:8080/
</VirtualHost>

Notice the /api route for the routing that goes to the embedded Tomcat at port 8080 (you can't use port 80 or it will conflict with Apache Server already listening on port 80), else if it's just / , then it will not allow traffic to base website anymore (alpizano.me), which isn't what I wanted.注意/api路由在 8080 端口进入嵌入式 Tomcat 的路由(你不能使用端口 80 否则它会与 Apache 服务器冲突),否则如果它只是/ ,那么它不会允许不再访问基础网站(alpizano.me),这不是我想要的。

This wouldn't be needed if you just had a standalone app that you wanted to route traffic, then you could just use / as your route obviously.如果您只有一个想要路由流量的独立应用程序,则不需要这样做,那么您显然可以使用/作为您的路线。 I saw other posts talking about forwarding the headers but that didn't seem to make a difference for me and I believe ProxyPreserveHost On takes care of that anyway我看到其他帖子谈论转发标头,但这对我来说似乎没有什么不同,我相信ProxyPreserveHost On无论如何都会解决这个问题

Good luck.祝你好运。

References:参考:

https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 杀死进程(数字海洋ubuntu水滴) - killed process (digital ocean ubuntu droplet) 无法从端口80的Linux中的Eclipse Juno启动Apache tomcat - Failed to Start Apache tomcat from eclipse juno in linux at port 80 无法在 linux 服务器(数字海洋)中安装 tensorflow - cant install tensorflow in linux server (digital ocean) 如何在Linux服务器上的端口80上启动node.js? - How to start node.js on port 80 on a linux server? 无法修复 NGINX 502:Digital Ocean 液滴上的网关错误 - Ubuntu 20.04 - Unable to fix NGINX 502: Bad Gateway error on a Digital Ocean droplet - Ubuntu 20.04 在LAMP液滴上安装Vesta面板(数字海洋) - Install Vesta panel on LAMP droplet (Digital Ocean) Digital Ocean Droplet 重启恢复模式 - Digital Ocean Droplet Restart Recovery Mode Ubuntu 20.04 上的 NodeJS - 无法启动服务器,因为地址正在使用 (:::80) 但我找不到任何侦听该地址的端口 - NodeJS on Ubuntu 20.04 - Cannot start server because address in use (:::80) but I can't find any port listening to that address 无法将Spring Boot应用程序启动到Linux服务器中 - Failed to launch Spring boot application into Linux server 在端口80(Linux)中从Eclipse启动Tomcat - Start Tomcat from Eclipse in port 80 ( Linux )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM