如何通过IP访问我的localhost:8080?

时间:2017-12-14 13:49:06

标签: node.js ubuntu nginx gcp

我在GCP上运行了nodeJs。我使用nodejs创建了一个简单的HelloWorld程序。在我运行helloworld的那一刻,它从http://localhost:8080开始。为了访问它,GCP为我提供了内部和外部IP。

现在我想要的是,如果我只是输入xx.xx.xx.xx(外部IP)/ nodejs,它就会打开http://localhost:8080。表示xx.xx.xx.xx / nodejs打开我的HelloWorld节点。我想这可以通过nginx来完成。那么有人能让我知道这有可能吗?

提前谢谢。

1 个答案:

答案 0 :(得分:0)

这很简单。您应该将proxy_pass用于其位置为/ nodejs的请求,并将它们发送到localhost:8080。这就像是:

server {
    listen       80;
    ...
    location /nodejs {
        proxy_pass http://127.0.0.1:8080;
    }
    ...
}