For better performance, we suggest using Nginx as a reverse proxy for terminating SSL connections and with help of push-stream module to speed-up overall application (chat and agent panel) performance.

Step 1: Install Nginx

If you want to use Nginx only for SSL termination just install it with your usual distribution installation tool. For example on centos, you could use

yum install nginx

Then don't forget to enable it on server startup with

chkconfig nginx on

If you want to speed up the LiveAgent application with the usage of the push-stream module you need to compile Nginx with it. Author of the module provides a good guide for it. When compiling do not forget to enter properly all the required parameters. You can find some guidance here or directly on Nginx pages. Do not forget to compile your instance with push-stream module!

After everything is compiled/installed it is time to setup LiveAgent installation. Create configuration Nginx file for your LiveAgent installation. For example it can be located in /etc/nginx/conf.d/liveagent.conf.

The file should contain configuration like this:

#private push-stream listen location 
server {
        listen       localhost:8060;
        server_name  localhost;

        location /event/channels-stats {
                push_stream_channels_statistics;
                push_stream_channels_path               $arg_id;
        }

        location /event/publish {
                push_stream_publisher admin;
                push_stream_channels_path                       $arg_id;
                push_stream_store_messages on;
        }
    }

#public LiveAgent configuration
server
 {
        listen       80;
        server_name  mysupport.example.com;
        
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto "http"; 
        
        client_max_body_size       20m;
        client_body_buffer_size    128k;
    
        proxy_connect_timeout      900;
        proxy_send_timeout         900;
        proxy_read_timeout         900;
    
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k; 

        location ~ /event/ws {
            push_stream_subscriber websocket;

            push_stream_channels_path                   $arg_channels;
            push_stream_last_received_message_time      "$arg_time";
            push_stream_last_received_message_tag       "$arg_tag";

            push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";

            push_stream_ping_message_interval           10s;
        }        
        
        location ~ /event/lp {
            push_stream_subscriber      long-polling;
            
            push_stream_channels_path                   $arg_channels;

            push_stream_last_received_message_time      "$arg_time";
            push_stream_last_received_message_tag       "$arg_tag";

            push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";

            push_stream_longpolling_connection_ttl        30s;
        }        
        
        location ~ /event/sub {
            push_stream_subscriber;

            push_stream_channels_path                   $arg_channels;

            push_stream_last_received_message_time      "$arg_time";
            push_stream_last_received_message_tag       "$arg_tag";

            push_stream_header_template                 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
            push_stream_message_template                "<script>p(~id~,'~channel~','~text~','~event-id~', '~time~', '~tag~');</script>";
            push_stream_footer_template                 "</body></html>";
            
            default_type                                "text/html; charset=utf-8";
            
            push_stream_ping_message_interval           10s;
        }
            
        location ~ /event/ev {
            push_stream_subscriber eventsource;

            push_stream_channels_path                   $arg_channels;

            push_stream_last_received_message_time      "$arg_time";
            push_stream_last_received_message_tag       "$arg_tag";

            push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";

            push_stream_ping_message_interval           10s;
        }
        
        location / {
            proxy_pass   https://127.0.0.1:6081; ### point this to your varnish or directly to apache!
            proxy_redirect     off;
        }
    }

Now your Nginx is accepting also push-stream notifications. Notice location "/" that needs to be pointed to your cache server listen location - Varnish  (if you have one) or directly to your httpd server  (Apache right?).

The last step is to tell the application to use the push-stream module. You need to add this line to your settings.php in your accounts/ directory in your LiveAgent installation folder.

PUSHSTREAM_SERVER=127.0.0.1:8060

this should point to your local Nginx listen IP and port you configured in your Nginx configuration file.

How can you tell that it is working? Well, messages from any chat window should appear in agent (and vice versa) panel almost instantly. Without push-stream module there is usually slight delay (50-100ms) - depends on the amount of traffic on your pages and number of chats.

 

×