将 NGINX proxy_pass 添加到 Redis 和 mongodb 出现错误

问题描述 投票:0回答:1

我需要通过nginx代理redis和mongodb。

这是 /etc/nginx/nginx.conf 中的配置文件。

stream {
    server {
        listen  27030;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass stream_mongo_backend;
    }

    upstream stream_mongo_backend {
        server  127.0.0.1:27027;
    }

}

然后重启服务器就运行没有任何问题了。

但是添加 redis 代理配置时如下所示。

stream {
    server {
        listen  27030;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass stream_mongo_backend;
    }

    upstream stream_mongo_backend {
        server  127.0.0.1:27027;
    }

    server {
        listen  6379;
        proxy_pass stream_redis_backend;
    }

    upstream stream_redis_backend {
        server  127.0.0.1:6379;
    }

}

运行 nginx 时出现错误提示

 nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2024-08-25 10:37:15 CST; 2min 17s ago
       Docs: man:nginx(8)
    Process: 3828683 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 3828684 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 32ms

Aug 25 10:37:12 iZbp1cszroygcwaqhf9sk1Z nginx[3828684]: nginx: [warn] server name "http://app.xx.com/" has suspicious symbols in /etc/nginx/sites-enabled/**default:24**

这是站点配置

server {

       listen 80 default_server;
       listen [::]:80 default_server;
       # Default server configuration
        server_name http://app.xx.com/;   // line 24
        location / {
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header Host $http_host;
             proxy_set_header X-Forwarded-Proto $scheme;
             proxy_pass http://127.0.0.1:3000; # SSL configuration
        }
}


server {
       # Default server configuration
    server_name app.xx.com; # managed by Certbot

        location / {
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header Host $http_host;
             proxy_set_header X-Forwarded-Proto $scheme;
             proxy_pass http://127.0.0.1:3000; # SSL configuration
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/app.kuangcc.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/app.kuangcc.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = app.kuangcc.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

       listen 80 ;
       listen [::]:80 ;
       server_name app.xx.com;
       return 404; # managed by Certbot

}

还是没找到问题所在,请帮忙

nginx redis
1个回答
0
投票

您不能在配置文件的

server_name
中使用斜杠。
尝试将其更改为:

server {

   listen 80 default_server;
   listen [::]:80 default_server;
   # Default server configuration
    server_name app.xx.com;
    location / {
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header Host $http_host;
         proxy_set_header X-Forwarded-Proto $scheme;
         proxy_pass http://127.0.0.1:3000; # SSL configuration
    }

}

© www.soinside.com 2019 - 2024. All rights reserved.