DevOps/Linux

ssl websocket (wss) 설정

mingmingIT 2017. 11. 30. 10:17
1. 프로세스
     (1) 서버가 실행되면서 websocket 준비
     - setAllowedOrigins("*") 을 작성해야 wss 통신 가능
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
      registry.addHandler(videoDataHandler(), "/livevideo").setAllowedOrigins("*");
}

     (2) 호출 ws (or) wss://domain:port/livevideo
var wsketSrc = "";
if(protocol == "https:") {
    wsketSrc = 'wss://' + domain + '8443/livevideo?DeviceId=' + device_id + '&Channel=' + channel;
} else {
    wsketSrc = 'ws://' + domain + ':'+ port + '/livevideo?DeviceId=' + device_id + '&Channel=' + channel;
}
wsInfo.ws = new WebSocket(wsketSrc);

     (3) afterConnectionEstablished 메소드 실행 http로 api 호출
VideoStream stream = streamMap.get(channel);
if (dvr.getNetwork_connected()) {
    if (stream == null) {
        stream = new VideoStream();
        streamMap.put(channel, stream);
        String cmdString = "acms://livevideo.cgi?Uri=http://"+dvr.getAcms_host()+"/dvr/livestream/web&DeviceId="
                + device_id + "&Channel=" + channel+"&Audio=0\r\n\r\n";
        dvr.pushCmd(cmdString);
        System.out.println("###cmdString### : "+ cmdString);
    }
}else{
    session.close(CloseStatus.PROTOCOL_ERROR);
    return;
}
VideoConsumer dispatcher = stream.getVideoConsumer();
dispatcher.addSession(session.getId(), session);


2. apache 세팅
     (1) apache2 설정
     - /etc/apache2/ports.conf
Listen 80
Listen 8443

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>


     - /etc/apache2/sites-enabled/default-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ProxyPreserveHost On
        # Servers to proxy the connection, or
        # List of application servers Usage
        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
        ServerName localhost

        SSLEngine on
        SSLCertificateFile      /etc/ssl/certs/acms.bft-ltd.co.uk.crt
        SSLCertificateKeyFile /etc/ssl/private/acms.bft-ltd.co.uk.key
        SSLCertificateChainFile /etc/ssl/certs/intermediate.crt
</VirtualHost>
<VirtualHost _default_:8443>
        ServerAdmin webmaster@localhost
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/
        ErrorLog ${APACHE_LOG_DIR}/error_ws.log
        CustomLog ${APACHE_LOG_DIR}/access.ws.log combined
        ProxyPreserveHost On
        # Servers to proxy the connection, or
        # List of application servers Usage
        ProxyPass / ws://localhost:8080/
        ProxyPassReverse / ws://localhost:8080/
        ServerName localhost

        SSLEngine on
        SSLCertificateFile      /etc/ssl/certs/acms.bft-ltd.co.uk.crt
        SSLCertificateKeyFile /etc/ssl/private/acms.bft-ltd.co.uk.key
        SSLCertificateChainFile /etc/ssl/certs/intermediate.crt

</VirtualHost>
</IfModule>

     (2) 80, 8443 포트포워딩





'DevOps > Linux' 카테고리의 다른 글

tracert 사용  (0) 2017.11.30
시스템 시간 동기화  (0) 2017.11.30
hostname 변경 방법  (0) 2017.11.30
우분투에 tomcat 설치 및 자동시작  (0) 2017.11.30