パフォーマンスを向上させるために、SSLの終端処理にNginxをリバースプロキシとして使用し、push-streamモジュールを活用してアプリケーション全体(チャットおよびエージェントパネル)のパフォーマンスを高めることをお勧めします。

手順1:Nginxのインストール

SSLの終端処理のみにNginxを使用する場合は、ご利用のディストリビューションの通常のインストールツールでインストールしてください。例えばCentOSの場合、以下のコマンドを使用できます。

yum install nginx

次に、サーバー起動時に自動起動するよう設定することを忘れずに行ってください。

chkconfig nginx on

push-streamモジュールを使用してLiveAgentアプリケーションを高速化する場合は、モジュールを組み込んだ状態でNginxをコンパイルする必要があります。モジュールの作者がわかりやすいガイドを提供しています。コンパイル時には、必要なパラメーターをすべて正しく入力してください。こちらまたはNginxの公式ページでも参考情報を確認できます。push-streamモジュールを含めてコンパイルすることを忘れないでください。

コンパイル/インストールが完了したら、LiveAgentのセットアップを行います。LiveAgentインストール用のNginx設定ファイルを作成してください。例えば、/etc/nginx/conf.d/liveagent.confに配置することができます。

ファイルには以下のような設定を記述します。

#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;
        }
    }

これでNginxがpush-stream通知を受け付けるようになります。location “/“はキャッシュサーバーのリッスンアドレス(Varnishを使用している場合)、またはhttpdサーバー(Apache)に直接向ける必要がある点に注意してください。

最後に、アプリケーションにpush-streamモジュールを使用するよう設定します。LiveAgentインストールフォルダ内のaccounts/ディレクトリにあるsettings.phpに以下の行を追加してください。

PUSHSTREAM_SERVER=127.0.0.1:8060

この設定は、Nginx設定ファイルで指定したローカルNginxのリッスンIPとポートを指定します。

正常に動作しているかどうかはどうすれば確認できますか?チャットウィンドウからのメッセージがエージェントパネルにほぼ瞬時に表示されれば(またはその逆も同様)、正常に動作しています。push-streamモジュールを使用しない場合、ページのトラフィック量やチャット数によって、通常50〜100ms程度の遅延が生じます。