Google cloud platform google云平台:无法启动java https服务器
下面是一个简单的程序:Google cloud platform google云平台:无法启动java https服务器,google-cloud-platform,java-server,Google Cloud Platform,Java Server,下面是一个简单的程序: import com.sun.net.httpserver.HttpsServer; import java.net.InetSocketAddress; class SimpleServer { public static void main(String[] pArgs) { try { HttpsServer s = HttpsServer.create(new InetSocketAddress(443), 0); Syste
import com.sun.net.httpserver.HttpsServer;
import java.net.InetSocketAddress;
class SimpleServer {
public static void main(String[] pArgs) {
try {
HttpsServer s = HttpsServer.create(new InetSocketAddress(443), 0);
System.out.println(" " + s);
} catch (Exception pE) {
throw new RuntimeException("Could not create HTTPS server", pE);
}
}
}
在由google云平台(google Compute Engine-IaaS)托管的Debian虚拟机中无法工作:
这不是GCP问题,而是linux/Unix安全特性 linux/Unix上低于1024的端口是“特权端口”,需要提升权限才能创建 在GCP中,您有几个选项 使用1024以上的高端口作为非特权用户,并且:
- 连接到url中的高端口https://foo:8443
- 使用GCP网络或HTTP/HTTPS负载平衡器将端口443转发到高端端口
- 利用IP表将数据包从443转发到VM实例内的高端口
- 使用suid、sudo或其他方法运行服务
- 向进程授予_CAP_NET_BIND_SERVICE_功能(7)
.这不是GCP问题,而是linux/Unix安全特性 linux/Unix上低于1024的端口是“特权端口”,需要提升权限才能创建 在GCP中,您有几个选项 使用1024以上的高端口作为非特权用户,并且:
- 连接到url中的高端口https://foo:8443
- 使用GCP网络或HTTP/HTTPS负载平衡器将端口443转发到高端端口
- 利用IP表将数据包从443转发到VM实例内的高端口
- 使用suid、sudo或其他方法运行服务
- 向进程授予_CAP_NET_BIND_SERVICE_功能(7)
.似乎有帮助的是对上面的程序进行“sudo”,这可能是唯一/最终的答案,但这可以在没有权限提升的情况下完成吗?似乎有帮助的是对上面的程序进行“sudo”,这可能是唯一/最终的答案,但这可以在没有权限提升的情况下完成吗?
Exception in thread "main" java.lang.RuntimeException: Could not create HTTPS server
at SimpleServer.main(SimpleServer.java:10)
Caused by: java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:100)
at sun.net.httpserver.HttpsServerImpl.<init>(HttpsServerImpl.java:50)
at sun.net.httpserver.DefaultHttpServerProvider.createHttpsServer(DefaultHttpServerProvider.java:39)
at com.sun.net.httpserver.HttpsServer.create(HttpsServer.java:90)
at SimpleServer.main(SimpleServer.java:7)
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-8u141-b15-1~deb9u1-b15)
OpenJDK 64-Bit Server VM (build 25.141-b15, mixed mode)