Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to properly stream everything behind nginx proxy? #858

Open
ralyodio opened this issue Dec 2, 2024 · 9 comments
Open

how to properly stream everything behind nginx proxy? #858

ralyodio opened this issue Dec 2, 2024 · 9 comments

Comments

@ralyodio
Copy link

ralyodio commented Dec 2, 2024

I am using docker and it appears to work but the nginx isn't setup properly for streaming (no data is coming through):

server {
    server_name	stream.profullstack.com;
    index index.html;
    root /home/ubuntu/www/profullstack.com/stream;

    add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    add_header 'Last-Modified' '';
    if_modified_since off;
    expires -1;
    etag off;

    listen [::]:443 ssl http2; #managed by Certbot
    listen 443 ssl http2; #managed by Certbot
    ssl_certificate /etc/letsencrypt/live/stream.profullstack.com/fullchain.pem; #managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/stream.profullstack.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

    #try_files $uri $uri/ /index.html;
    client_max_body_size 10M;

    location ~ /\. {
        deny all;
        return 403;
    }

    location /restreamer/ {
        proxy_pass http://127.0.0.1:8080/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_cache_bypass $http_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
}

what else do i need to add?

@ralyodio
Copy link
Author

ralyodio commented Dec 3, 2024

bump

@ioppermann
Copy link
Member

Please consult our guide on proxying: https://docs.datarhei.com/restreamer/knowledge-base/user-guides/proxying

If you are running nginx in a Docker container separate from Restreamer, then you have to adjust the IP the proxy_pass directive is pointing to. In order to connect from one container to another, this guide might be helpful: https://docs.docker.com/engine/network/tutorials/standalone/

@ralyodio
Copy link
Author

ralyodio commented Dec 6, 2024

That proxying doc isn't very good. I'm confused. It really only shows how to proxy 8080 which works fine for me.

@ralyodio
Copy link
Author

ralyodio commented Dec 6, 2024

http {
    server {
        listen 80;
        server_name ...;

        [your site configuration]

        location /restreamer/ {
            proxy_http_version 1.1;
            proxy_pass http://192.168.1.42:8080/;
            proxy_redirect off;
        }
    }
}

stream {
    server {
        listen 1935;
        proxy_pass 192.168.1.42:1935;
    }

    server {
        listen 6000 udp reuseport;
        proxy_pass 192.168.1.42:6000;
    }
}

what is the 2nd block? I don't understand

@ioppermann
Copy link
Member

nginx is usually only proxying HTTP requests. The 2nd block is for proxying RTMP (port 1935) and SRT (port 6000 via UDP).

@ralyodio
Copy link
Author

can i modify routes at all? like I want stream to work off location /restreamer somehow.

@ioppermann
Copy link
Member

Yes, the route can be modified, e.g. location /camera1/.

@ralyodio
Copy link
Author

so i still can't get this to work. I try to publish to rtmp url and it doesn't recognize it.

@ioppermann
Copy link
Member

The location block is only for HTTP requests. For publishing RTMP you first have to enable RTMP in Restreamer and then configure the stream block in nginx properly:

stream {
    server {
        listen 2035;
        proxy_pass 127.0.0.1:1935;
    }
}

where you have to adjust the IP to the IP where Restreamer is running. If it is running on the same box, the IP will be 127.0.0.1. In this case you have also to consider that nginx and Restreamer can't listen on the same port 1935 at the same time. A solution to this would be to change the listening port to eg. 2035 in the nginx configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants