2015-11-20 90 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禁止。有什麼可以想到會導致這種情況嗎? –