Is it possible to use two pub/sub setups in one nginx?

45 views
Skip to first unread message

Ian Hobson

unread,
Feb 14, 2017, 7:42:42 AM2/14/17
to nginxpushstream
Hi,

I have what appears to be a configuration problem, but I am not sure.

I have set up https://masterdomain.com/ as a chat room, and everything works as expected. The system uses nginx, php and the long polling module. The data from the messagtes is logged into the database and then posted to /publish using php's curl_exec. 

I am now trying to set up https://resellersdomain.com/  as a chat room that shares code with the masterdomain, but serves files (images css and php) from its own directory structure if they exist. I intend it to use its own /publish and /activity URLs so messages do not get shared between domains. This permits the reseller to brand the chat room.

All that works very well, except for the message passing.

Both configurations have identical long polling setups (see below) and share common code to post to /publish (see further below).

The /publish url is accessed by  php's curl_exec.
The code posts to https://resellersdomain.com/publish with the parameters I expect.
The post does not fail.
However the activity log from nginx reports that the reply was a 404!!!
And I get nothing from /activity

However if I use masterdomain.com, everything works as expected!

Here is the long polling set up (Both are identical).

    # now to configure the long polling
    push_store_messages on;
    location /publish {
        push_publisher;
        set $push_channel_id $arg_id;
        push_message_timeout 30s;
        push_max_message_buffer_length 10;
    }
    # public long-polling endpoint
    location /activity {
        push_subscriber;
        push_subscriber_concurrency broadcast;
        set $push_channel_id $arg_id;
        default_type  text/plain;
    }

The php to post to publish is shared by both systems....

// now to post to message queue
//
$channel = sprintf("%u", crc32($SHOP.$SessionID));
$host = $_SERVER['HTTP_HOST'];        //  domain from user
$protocol = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])!= "OFF")? "https" : "http";
$url = "$protocol://$host/publish?id=$channel" ;
// convert to json
Logger::theLog()->log("Curl_exec to $url",2);
$data = json_encode(array($action, $NIC, $content, $attends['Colour'], $people, $insert_id));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER,
        Array("Content-Type: 'application/x-www-form-urlencoded",
            'Cache-Control: private'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  // read data
curl_setopt($ch, CURLOPT_POST, true);            // do a post
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// next two options to disable verify - so self cert works and can be tested
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

Logger::theLog()->log("writing $data" , 2);
$rec_data = curl_exec($ch);
//Logger::theLog()->log("rec_data = ".$rec_data , 4);
if ($rec_data === false) {
    Logger::theLog()->log("curl_exec failed :".curl_error($ch) , 2);
    echo curl_error($ch);
} else {
    Logger::theLog()->log("curl_exec succeeded ", 3);
}
curl_close($ch);

Logger reports what I expect.
Both sets of certificates are self signed.
Both domains resolve to 127.0.0.1 on the server.

I am stumped and don't know how to further debug things. Any ideas and help gratefully received!

Thanks
Ian

Ian Hobson

unread,
Feb 14, 2017, 10:33:55 AM2/14/17
to nginxpushstream
Cracked it!

I have two places where I pass the request over to PHP in the nginx setup for the reseller: one for the reseller's php file, if it exists, and one for the masterfile when the reseller's file does not exist.

I had omitted a  "fastcgi_param HTTPS ON;" line in one of these locations.

All is now working.

Wandenberg Peixoto

unread,
Feb 14, 2017, 11:58:53 AM2/14/17
to nginxpu...@googlegroups.com
OK. Anyway, unless you made a typo on your first email, you are using the wrong group for talk about the module.
You seems to be using the push module and this group is for push_stream module. They are different, maintained by two different person and have different directives. I am even not sure if the other one is having maintenance.
;)

--
You received this message because you are subscribed to the Google Groups "nginxpushstream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginxpushstream+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages