使用 Spring 以非 root 用户身份在端口 80 上启动 bootRun 进程

问题描述 投票:0回答:3

我尝试以非 root 用户身份使用端口 80,并且我已经看到有关使用 IP 表的讨论,但我想使用 tomcat 配置文件来修改这些绑定。有一个选项

AUTHBIND
允许使用端口 <1024 but I have no idea where the Spring tomcat files are located... There is no tomcat service running when I start my Spring process so where is the Spring tomcat server actually located? Where can I see the configuration files etc?

java spring tomcat port
3个回答
3
投票

我认为你的方法是错误的。我不建议你尝试直接使用HTTP 80端口。

一个好的做法是使用 Apache HTTP Server 重定向或别名:

说明:

您将使用“经典”端口(例如 8080 或 9080 或任何其他超过 1024 的端口)启动 Tomcat。然后,您将配置 Apache 服务器以将 HTTP 请求从 HTTP 端口 80 重定向到 Tomcat 服务器。


0
投票

您可以运行此命令

sudo su -
setcap 'cap_net_bind_service=+ep' $(which java) # or if you put java path directly for example /usr/lib/jvm/bellsoft-java21-amd64/bin/java

这将允许用户以非 root 权限使用低于 1024 的端口。


-2
投票
Do follow steps:
1. Go to your application.properties if it doesn't exist.
2. Create a application.properties inside src/main/resources folder.
 example->/src/main/resources/application.properties
3. Simply add this property  server.port = 80 or if you want it to be random do server.port = 0
© www.soinside.com 2019 - 2024. All rights reserved.