0

So I've found NginX's official tutorial, how to use NginX Plus as the proxy for the MariaDB Cluster. However, if I do this with my standard NginX (not the Plus edition) I constantly get the error nginx: [emerg] invalid URL prefix in /etc/nginx/conf.d/mariadb.conf:10

Here is the config

upstream db {
    server 10.0.0.101:3306;
    server 10.0.0.102:3306;
    server 10.0.0.103:3306;
}

server {
    listen 3306;
    location / {
        proxy_pass db;
        proxy_connect_timeout 1s;
    }
}

My question if this is only available on NginX Plus or I'm doing something wrong? I'm aware, that normally I need a prefix in the proxy_pass like https:// but in this case?

Bert
  • 1,028
  • 1
  • 16
  • 33

1 Answers1

1

You need to remove the location / {} stuff. This is for http servers, not for plain TCP. And you need to wrap it into a stream block.

stream {
    upstream db {
        server 10.0.0.101:3306;
        server 10.0.0.102:3306;
        server 10.0.0.103:3306;
    }

    server {
        listen 3306;
        proxy_pass db;
        proxy_connect_timeout 1s;
    }
}

You can find the documentation here: https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • If I do that, then the error message changes to: `"proxy_pass" directive is not allowed here`. I've included the location because of this specific reason. :/ Also, the stream is included in `nginx.conf` and inside stream I've written `include /etc/nginx/conf.d/*.conf` – Bert Jul 31 '20 at 13:37
  • I guess then this really is only possible with NginX Plus. I never used it that way, so I can't tell for sure. – Gerald Schneider Jul 31 '20 at 14:00
  • This should work fine, provided nginx is 1.9.0 or higher. Something else is wrong with the config, most likely. Look at `nginx -T`. – Michael Hampton Jul 31 '20 at 15:08