nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/nginx.conf:25

224 Views Asked by At

I've been trying to get this reverse proxy working for my FiveM server for the whole day, and it's getting onto my nerves pretty hard right now.

I've went through thousand of questions and forums to try and find a solution, but none worked.

Here's my detailed nginx.conf (anonymised obv)

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;  # Corrected indentation: ensure this has no leading spaces 
}

http {

    server { # Your `play.domain.gg` server config for HTTP traffic
        listen 80; 
        listen [::]:80; # Listen for IPv4 & IPv6 
        server_name play.domain.gg; 

        location / { 
            proxy_pass http://1.1.1.1:30120; # main host
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

    stream {  #  Stream block now nested within 'http' for correct context
        upstream backend {
            server 1.1.1.1:30120; 
        }
        server {
            listen 30120;
            proxy_pass backend;
        }
        server {
            listen 30120 udp reuseport;
            proxy_pass backend;
        }
    } 

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;

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

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Just as a quick information, I'm trying to create a reverse proxy for my FiveM server so that players can connect using a url instead of an IP.

I tried following the documentation given by CFX but it's not the most detailed one. I also tried using Gemini AI to help me, but it got me nowhere.

The error I get whenever I run the command : nginx -t

nginx -t
nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/nginx.conf:25
nginx: configuration file /etc/nginx/nginx.conf test failed

I'm completely lost. If anyone has an idea please lmk.

0

There are 0 best solutions below