无法从子文件夹中提供expressjs app

时间:2016-11-13 06:35:09

标签: express nginx

我是表达和nginx的新手。

我制作了一个简单的快递应用并配置了nginx:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stopwatch);

    if(savedInstanceState != null)
    {
        seconds = savedInstanceState.getInt("seconds");
        running = savedInstanceState.getBoolean("running");
        wasRunning = savedInstanceState.getBoolean("wasRunning");
    }

    runTimer();
}

我的expressjs应用程序是:

location /exapi {
    proxy_pass http://localhost:8010;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

当我访问我的vps VPS_IP / exapi时,我收到回复 var express = require('express') var app = express() app.get('/', function (req, res) { res.send('Hello World!') }) app.listen(8010, function () { console.log('Example app listening on port 8010!') }) ,但当我使用Cannot GET /exapi时,它正在按预期工作。

如何从http://VPS_IP:8010访问我的快递应用程序?

1 个答案:

答案 0 :(得分:1)

尝试在nginx中重写:

location ~* ^/exapi {
    rewrite ^/exapi/(.*) /$1 break;
    subfilter /exapi /;

    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_pass http://localhost:8010;
}