0

几天来,我一直在尝试在 aws ec2 上启动一个文档记录不佳的游戏应用程序(帮助朋友),作为一个完整的游戏和 bash-rookie,最终设法启动它;但不像在声明的 playShop.sh 文件中那样监听端口 8080,而是在随机端口 (8081) 上监听,因为 8080 引发了“已在使用”-异常。

playShop.sh(更改了端口):

sudo nohup ./start -Dconfig.file=/home/ec2-user/prod.conf -Dhttp.port=8081 -Dhttp.address=127.0.0.1 &

开始

!/usr/bin/env sh

执行 java $* -cp " dirname $0/lib/*" play.core.server.NettyServerdirname $0

到目前为止,一切都很好!但是我现在如何通过网络浏览器访问它?当我调用公共 DNS 时,我会进入一个标准的欢迎页面。我尝试在该端口上设置安全组设置(quicklaunch1-->inbound)并使用负载均衡器-->侦听器,但没有任何帮助。

这似乎是漫长旅程的最后一步,欢迎任何帮助!谢谢。

编辑:这是 nohup.out 在这两个端口上登录的内容:

    Play server process ID is 1593
[[37minfo[0m] play - Application started (Prod)
Oops, cannot start the server.
org.jboss.netty.channel.ChannelException: Failed to bind to: /127.0.0.1:8080
    at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:298)
    at play.core.server.NettyServer.<init>(NettyServer.scala:63)
    at play.core.server.NettyServer$.createServer(NettyServer.scala:132)
    at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:162)
    at play.core.server.NettyServer$$anonfun$main$5.apply(NettyServer.scala:161)
    at scala.Option.map(Option.scala:133)
    at play.core.server.NettyServer$.main(NettyServer.scala:161)
    at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind(Native Method)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:137)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:77)
    at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.bind(NioServerSocketPipelineSink.java:138)
    at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleServerSocket(NioServerSocketPipelineSink.java:90)
    at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:64)
    at org.jboss.netty.channel.Channels.bind(Channels.java:569)
    at org.jboss.netty.channel.AbstractChannel.bind(AbstractChannel.java:187)
    at org.jboss.netty.bootstrap.ServerBootstrap$Binder.channelOpen(ServerBootstrap.java:343)
    at org.jboss.netty.channel.Channels.fireChannelOpen(Channels.java:170)
    at org.jboss.netty.channel.socket.nio.NioServerSocketChannel.<init>(NioServerSocketChannel.java:80)
    at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:158)
    at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.newChannel(NioServerSocketChannelFactory.java:86)
    at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:277)
    ... 7 more
Play server process ID is 1650
[[37minfo[0m] play - Application started (Prod)
[[37minfo[0m] play - Listening for HTTP on port 8081..

.

4

1 回答 1

0

到目前为止,一切都很好!但是我现在如何通过网络浏览器访问它?当我调用公共 DNS 时,我会进入一个标准的欢迎页面。我尝试在该端口上设置安全组设置(quicklaunch1-->inbound)并使用负载均衡器-->侦听器,但没有任何帮助。

当您使用 Web 浏览器访问域名时,默认情况下它会尝试连接到端口 80。要解决此问题,您必须像这样访问它:

http://myserver.com:8081/ 

这对用户来说很难。为了解决这个问题,推荐的方法是使用代理服务器来处理来自客户端的标准请求,该客户端侦听端口 80 并根据需要将请求转发到应用程序服务器(播放服务器)。我通常为此推荐 nginx,play 框架主页有一个基本的设置指南。在您的情况下,它将类似于:

http {

  proxy_buffering    off;
  proxy_set_header   X-Real-IP $remote_addr;
  proxy_set_header   X-Scheme $scheme;
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header   Host $http_host;

  upstream my-backend {
    server 127.0.0.1:8081;
  }

  server {
    server_name www.mysite.com mysite.com;
    rewrite ^(.*) https://www.mysite.com$1 permanent;
  }

  server {
    listen               443;
    ssl                  on;
    ssl_certificate      /etc/ssl/certs/my_ssl.crt;
    ssl_certificate_key  /etc/ssl/private/my_ssl.key;
    keepalive_timeout    70;
    server_name www.mysite.com;
    location / {
      proxy_pass  http://my-backend;
    }
  }
}
于 2013-03-08T23:25:15.533 回答