Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform google云平台:无法启动java https服务器_Google Cloud Platform_Java Server - Fatal编程技术网

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)