2015-11-20 68 views
0

所以我有一个应用程序,在http://localhost:4206上启动一个web服务。配置nginx添加转发代理?

我已将应用程序复制到EC2实例,现在要启动该服务,但允许每个人(外部消费者)打这个服务。我知道我可以配置nginx将端口8080(外部)的转发代理添加到我的服务器的端口(4206)。

我发现以下指南:https://ef.gy/using-nginx-as-a-proxy-server

不过,我不确定究竟是什么在这个指南我应该做...

应该这个片段看起来像什么我?

server { 
    listen  8080; 

    location/{ 
     resolver 8.8.8.8; 
     proxy_pass http://$http_host$uri$is_args$args; 
    } 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root html; 
    } 
} 

某些方向将不胜感激。谢谢!

+0

嗨,我不能确定这是否会真正帮助,所以我将在本注释。我之前实际上配置了nginx来代理在同一个ec2实例中运行的节点服务器以及一个php fpm。而我的配置是这个https://gist.github.com/nosweat/a1e991c9359b719459e1#file-php-node-nginx-conf-L34 – vincent

回答

1
server { 
    # Port 
    listen  8080; 

    # Set the name of the virtual server 
    server_name _; 

    # Proxy pass everything to http://localhost:4206/ 
    location/{ 
     proxy_pass http://localhost:4206; 
     # Set the proxied host 
     proxy_set_header Host localhost; 
    } 
} 

了解更多关于proxy_pass和其他指令这里:http://nginx.org/en/docs/http/ngx_http_proxy_module.html

+0

不幸的是,这给了我一个'!当我试图在EC2实例上启动服务时,java.net.BindException:地址已经在使用中。有任何想法吗? –

+0

你必须检查哪个进程正在使用端口 - 尝试'netstat -pant' –

+0

Gotcha - 如此杀死进程,现在尝试卷曲开发框,得到403禁止nginx错误。如果我在我的开发盒上启动服务,并在没有nginx转发代理的情况下curl localhost:4206,我不会得到这个403禁止。有什么可以想到会导致这种情况吗? –