站点nginx不工作错误显示504网关超时

发布于 2025-01-26 18:16:10 字数 1298 浏览 4 评论 0 原文

我已经购买了AWS Linux 2服务器来托管我的Web应用程序,

我已经发布了我的Web节点JS应用程序,并且想在默认IP上运行

我在/etc/nginx/nginx/sites-available/migrate.com.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.sstatic.net/1BD5X.png

I have purchased AWS linux 2 server to host My Web application

I have published My Web node js application and want to run on default IP

I have configured the below things in /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.sstatic.net/1BD5X.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹微笑 2025-02-02 18:16:10

指定端口 3000 您的节点应用程序也正在侦听,因为默认值为 80 http -

proxy_pass http:// /migrate.test.com:3000;

另外,如果您的nginx服务器与Node Application Server在同一计算机上运行,​​您也可以做 -

proxy_pass http:// localhost:3000;

Specify the port 3000 that your node application is listening on as well, since the default is 80 for http -

proxy_pass http://migrate.test.com:3000;

Also, if your nginx server is running on the same machine as your node application server, you can also do -

proxy_pass http://localhost:3000;

https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文