当前位置: 首页 > 知识库问答 >
问题:

nginx作为express server 504网关超时的反向代理

拓拔骁
2023-03-14
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            try_files $uri /index.html;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

如您所见,我创建了sites-available文件夹,然后在sites-enabled中进行链接,其中包括。

在网站内部-可用,我有一个文件与此:

# the IP(s) on which your node server is running. I chose port 3000.
upstream musiciansdb {
    server 127.0.0.1:3000;
    keepalive 8;
}

# the nginx server instance
server {
    listen 0.0.0.0:80;
    server_name musiciansdb.com musiciansdb;
    access_log /var/log/nginx/musiciansdb.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_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
            proxy_pass http://musiciansdb.com/;
        proxy_redirect off;

    }

}

NGINX的状况:

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-11-03 11:19:17 UTC; 2s ago
  Process: 937 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
  Process: 981 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 980 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 979 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 982 (nginx)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/nginx.service
           ├─982 nginx: master process /usr/sbin/nginx
           └─983 nginx: worker process

Nov 03 11:19:17 myserver.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Nov 03 11:19:17 myserver.localdomain nginx[980]: nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_size: 2048 or types_hasNov 03 11:19:17 myserver.localdomain nginx[980]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Nov 03 11:19:17 myserver.localdomain nginx[980]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 03 11:19:17 myserver.localdomain nginx[981]: nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_size: 2048 or types_hasNov 03 11:19:17 myserver.localdomain systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Nov 03 11:19:17 myserver.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
tcp6 0 0 :::3000 :::* LISTEN 3524/node

谢谢

共有1个答案

蔚和风
2023-03-14

这似乎是不好的路线。

proxy_pass http://musiciansdb.com/;

在nginx中创建上游后端时,以后必须以相同的名称引用它。

您有:

upstream musiciansdb {
server 127.0.0.1:3000;
keepalive 8;
}
proxy_pass http://musiciansdb;
 类似资料:
  • 我为我的应用程序创建了一个API网关,它将充当其他微服务的前端控制器。在我的生产设置中,我使用Nginx作为网关的反向代理 API网关在端口8080上运行 Nginx配置如下: gateway-api.conf: nginx中的超时设置。形态: Spring云网关gradle文件: 网关应用程序: 问题陈述: 在我的一个微服务中,一个REST API需要3分钟以上才能完成。如果我通过调用这个API

  • 我使用Nginx作为反向代理,它接收请求,然后执行proxy_pass以从运行在8001端口上的上游服务器获得实际的web应用程序。 如果我转到mywebsite.com或执行wget,我会在60秒后获得504网关超时...但是,如果我加载mywebsite.com:8001,应用程序将按预期加载! 和Nginx错误日志的输出:

  • null 我倾向于认为它是第一个,但在这种情况下,nginx不会是应用程序的入口...(这是个问题吗?)

  • 我设置nginx作为我的apache tomcat的反向代理。它像我预期的那样正常工作。然而,当Apache Tomcat服务器关闭时,NGINX总是返回502坏网关时,我感到困惑。而不是返回504坏网关超时? 502坏网关:服务器充当网关或代理,从上游服务器收到无效响应。 504网关超时服务器充当网关或代理,没有收到来自上游服务器的及时响应。 访问时出现错误日志: 2015/10/19 10:1

  • 主要内容:1. 代理服务器介绍,2. 将请求传递给代理的服务器,3. 传递请求标头,4. 配置缓冲区,5. 选择传出IP地址本文介绍代理服务器的基本配置。 您将学习如何通过不同协议将NGINX请求传递给代理的服务器,修改发送到代理服务器的客户端请求标头,以及配置来自代理服务器的响应缓冲。 代理服务器的基本配置目录 代理服务器介绍 将请求传递给代理的服务器 传递请求标头 配置缓冲区 选择传出IP地址 1. 代理服务器介绍 代理通常用于在多个服务器之间分配负载,无缝地显示来自不同网站的内容,或者通过

  • Nginx 是一个高性能的 HTTP 和反向代理服务器,代码完全用 C 实现,基于它的高性能以及诸多优点,我们可以把它设置为 hyperf 的前置服务器,实现负载均衡或 HTTPS 前置服务器等。 配置 Http 代理 # 至少需要一个 Hyperf 节点,多个配置多行 upstream hyperf { # Hyperf HTTP Server 的 IP 及 端口 server