我購買了 AWS linux 2 服務器來托管我的 Web 應用程式
我已經發布了我的 Web 節點 js 應用程式并希望在默認 IP 上運行
我在 /etc/nginx/sites-available/migrate.test.com 中配置了以下內容
# the IP(s) on which your node server is running. I chose port 3000.
upstream migrate.test.com {
server privateIPaddress:3000;
keepalive 8;
}
# the nginx server instance
server {
listen 80;
listen [::]:80;
server_name migrate.test.com;
access_log /var/log/nginx/migrate.test.com.log;
# pass the request to the node.js server with the correct headers
# and much more can be added, see nginx config options
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_read_timeout 3600;
proxy_pass http://migrate.test.com/;
proxy_redirect off;
}
}
```````
**My app.js code**
```````
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, "privateIPaddress");
console.log('Server running success');
``````
please check by browser output
[output][1]
[1]: https://i.stack.imgur.com/1BD5X.png
uj5u.com熱心網友回復:
指定您的節點應用程式正在偵聽的埠3000,因為默認值80是http-
proxy_pass http://migrate.test.com:3000;
此外,如果您的 nginx 服務器與節點應用程式服務器在同一臺機器上運行,您還可以執行以下操作 -
proxy_pass http://localhost:3000;
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/471255.html
標籤:节点.js nginx httpd.conf amazon-linux-2
