0
NGINXをリバースプロキシとして使用してExpressサーバを設定しようとしています。 NGINXは静的ファイルを、Expressは動的コンテンツを提供します。ExpressとNGINXで経路を設定する方法は?
問題:通常のルートリンク作品(website.com)が、私は(website.com/api)に移動したときに、私は404
nginxのからを得るこれが私のserver.jsです。
var express = require("express");
var app = express();
var server = app.listen(process.env.PORT || 5000);
console.log("Server Running");
app.get("/",function(req,res){res.send("HOME PAGE")});
app.get("/api", function(req, res) {
res.send('API PAGE');
});
これは私のnginxの設定ファイルである:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name website.com www.website.com;
location ~ ^/(assets/|images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
root /home/foobar/public; #this is where my static files reside
access_log off;
expires 24h;
}
location/{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://localhost:5000;
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;
try_files $uri $uri/ =404;
}
}