2016-11-13 51 views
2

我是新來表達和nginx。無法從子文件夾提供expressjs應用程序

我做了一個簡單明確的應用程序和配置nginx的:

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; 
} 

我expressjs程序是:

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!') 
}) 

當我訪問我的VPS VPS_IP/EXAPI,我得到響應Cannot GET /exapi,但是當我使用http://VPS_IP:8010它按預期工作。

如何從VPS_IP/exapi訪問我的快捷應用程序?在nginx的

+0

我已經upvoted這個,因爲它是一個一般清晰和準確的問題。但是,如果你可以在將來的問題中避免txtspk,那麼我們會很感激 - 因爲在這裏強制性地強制發佈帖子,讀者很欣賞把'plz'擴展爲'please'等額外的最小努力。謝謝! – halfer

+0

試試'location/exapi /'(帶有斜線) – robertklep

回答

1

嘗試重寫:

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

    proxy_set_header Host $host; 
    proxy_redirect off; 
    proxy_pass http://localhost:8010; 
} 
相關問題