Я приобрел сервер AWS linux 2 для размещения своего веб-приложения.
Я опубликовал js-приложение My Web node и хочу работать с 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.info('Server running success');
``````
please check by browser output
[output][1]
[1]: https://i.stack.imgur.com/1BD5X.png
Укажите порт 3000
, который также прослушивает ваше приложение узла, поскольку по умолчанию 80
для http
-
proxy_pass http://migrate.test.com:3000;
Кроме того, если ваш сервер nginx работает на том же компьютере, что и сервер приложений вашего узла, вы также можете сделать -
proxy_pass http://localhost:3000;
https://docs.nginx.com/nginx/admin-guide/веб-сервер/обратный-прокси/
Я обновил свой ответ. Можно еще проверить - docs.nginx.com/nginx/admin-guide/веб-сервер/обратный прокси
Я передаю IP-адрес своего сервера, но порт все еще не работает, я внес некоторые изменения, пожалуйста, просмотрите мой код один раз