[英]Is their a best practice to creating multiple applications using node and nginx as a proxy server?
我有 nginx 作為代理服務器以及幾個 node.js 應用程序運行。 我將 nginx 端口轉發到不同端口中的每個應用程序。 我有一個主服務器文件,在啟用站點的情況下如下所示:
server {
listen 80;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /app1 {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /app2 {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
每個應用程序都在 /var/www/html 目錄中運行以下代碼,並將端口變量分別分配給上述端口:
var http = require('http');
http.createServer(function(req,res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Under Construction\n');
}).listen(port, '127.0.01');
如果您有大量應用程序,則此文件看起來不可維護。 還有什么其他方法可以開發這個?
我使用 express 來監聽我需要的端口,而不必使用 nginx。
app.listen(port, function() {
console.log('listening on port ', port);
}
我不確定這是否是最佳實踐,但這已經從 nginx 中抽象了路由,以表達像 @jfriend00 建議的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.