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

Message IDs are not being forward to my upstream server #686

Open
bones2peaches opened this issue Mar 30, 2024 · 0 comments
Open

Message IDs are not being forward to my upstream server #686

bones2peaches opened this issue Mar 30, 2024 · 0 comments

Comments

@bones2peaches
Copy link

bones2peaches commented Mar 30, 2024

Hi Slact, thank you for making nchan it is sweet. I have encountered an error where the nchan_message_id variable and prev_message_id variable are not being forwarded to my upstream when using nchan_publisher_upstream_request. you can see from the logs that in the url and the headers of the requests the values are not there. would you know how to fix this? is it because I do not have redis pass in all of my publisher configurations only in my subscriber ?

I am using alpine linux , with version v1.3.6 see below for my configuration.
image



load_module "modules/ngx_nchan_module.so" ;
load_module "modules/ngx_http_headers_more_filter_module.so";



events {
}

http {

    access_log /dev/stdout;
    error_log /dev/stderr;
    more_clear_headers Server;
    server_tokens off;

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

    upstream api {
        server api:5000;
    }

    upstream redis_cluster {
        nchan_redis_server redis://redis-node-1:7000;
        nchan_redis_server redis://redis-node-2:7001;
        nchan_redis_server redis://redis-node-3:7002;
    }    


    server {

        listen 80;


        more_clear_headers Server;
        server_tokens off;
        # nchan_channel_group_accounting on;
        

        location = /health {
            default_type text/plain;
            return 200 'healthy\n';
        }



        # location ~ "/api/groups/([^/]+)$" {
        #     nchan_channel_group $1;
        #     nchan_group_location;
        #     nchan_group_max_channels $arg_max_channels;
        #     nchan_group_max_messages $arg_max_messages;
        #     nchan_group_max_messages_memory $arg_max_messages_mem;
        #     nchan_group_max_messages_disk $arg_max_messages_disk;
        #     nchan_group_max_subscribers $arg_max_subs;
        # }        

        location ~ "/api/nchan/chatroom/([^/]+)$" {
            internal;
            proxy_pass http://api/api/nchan/chatroom/$nchan_channel_id/$1?message_id=$nchan_message_id&prev_message_id=$nchan_prev_message_id;
            proxy_set_header X-Publisher-Type $nchan_publisher_type;
            proxy_set_header X-Message-Id $nchan_message_id;
            proxy_set_header X-Chatroom-Id $nchan_channel_id;
            proxy_set_header X-Prev-Message-Id $nchan_prev_message_id;
            proxy_set_header X-Original-URI $request_uri;
            
        }

        location = /api/nchan/unsubscribe {
            internal;
            proxy_pass http://api/api/nchan/unsubscribe;
            proxy_ignore_client_abort on;  #!!!important!!!!
            proxy_set_header X-Subscriber-Type $nchan_subscriber_type;
            proxy_set_header X-Channel-Id $nchan_channel_id;
            proxy_set_header X-Original-URI $request_uri;
        } 

        location = /api/nchan/subscribe {
            internal;
            proxy_pass http://api/api/nchan/subscribe;

            proxy_set_header X-Subscriber-Type $nchan_subscriber_type;
            proxy_set_header X-Channel-Id $nchan_channel_id;
            proxy_set_header X-Original-URI $request_uri;
        }

        location = /api/nchan/auth {
            internal;
            proxy_pass http://api/api/nchan/auth;
            proxy_pass_request_body off;
            proxy_set_header Content-Length "";
            proxy_set_header X-Subscriber-Type $nchan_subscriber_type;
            proxy_set_header X-Publisher-Type $nchan_publisher_type;
            proxy_set_header X-Prev-Message-Id $nchan_prev_message_id;
            proxy_set_header X-Channel-Id $nchan_channel_id;
            proxy_set_header X-Original-URI $request_uri;
            proxy_set_header X-Forwarded-For $remote_addr;
        }          
        
        location ~ "/api/chatroom/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/([^/]+)$" {
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' 'http://localhost:3000' always;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'authorization,content-type';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain; charset=utf-8';
                add_header 'Content-Length' 0;
                return 204;    
            }
            if ($request_method = 'POST') {

                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
                add_header 'Access-Control-Allow-Headers' 'authorization,content-type';
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
                add_header 'Access-Control-Max-Age' 1728000;
                nchan_publisher http;
                nchan_channel_id $1;
                nchan_publisher_upstream_request /api/nchan/chatroom/$2;  
 
            }
                
        }

        # location ~ "/internal/chatroom/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/([^/]+)$" {
        #         nchan_publisher http;
        #         nchan_channel_id $1;
        #         auth_basic "Restricted Content";
        #         auth_basic_user_file /etc/nginx/.htpasswd; 

        #     }
        location ~ "/internal/chatroom/((?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12},?)+)/([^/]+)$" {
            nchan_channel_id_split_delimiter ",";
            nchan_publisher http;
            nchan_channel_id $1;
            auth_basic "Restricted Content";
            auth_basic_user_file /etc/nginx/.htpasswd;
        } 
        location ~ "/ws/chatroom/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})" {
            nchan_subscriber websocket;
            nchan_channel_id $1;
            nchan_subscribe_request /api/nchan/subscribe;
            nchan_unsubscribe_request /api/nchan/unsubscribe;  
            nchan_authorize_request /api/nchan/auth;
            nchan_websocket_ping_interval 60;
            nchan_websocket_client_heartbeat hbin hbout;
            nchan_redis_pass redis_cluster;

        }

                location = /redis {
            nchan_redis_upstream_stats redis_cluster;
        }

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

No branches or pull requests

1 participant