본문 바로가기
서버/리눅스 서버

TVHeadend 4.3 버전 이상에서 리버스 프록시 설정하기

by ㅋㅋ잠자 2020. 2. 5.

안녕하세요? 


최근에 S사의 http 감지를 통해 tvh 연결을 막아버리면서, 아래와 같이 설정을 진행하게 되었습니다.


다만, htsp 를 사용하는 kodi 에서는 영향이 없습니다만, 9981 포트를 사용하는 부분에서는 문제가 생깁니다.



바로 시작하겠습니다.





1. 웹서버 설치 및 모듈 활성화 및 셀프 사인 인증서 생성


apt install apache2


a2enmod proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html ssl proxy_wstunnel


mkdir /etc/apache2/ssl


openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt





2. 사이트 설정 생성


기본 설정파일을 disable 하고 새로 하나 생성합니다.


a2dissite 000-default.conf


nano /etc/apache2/sites-available/tvheadend.conf


<Virtualhost *:80>

ServerName tvheadend.domain.com

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

</VirtualHost>


<VirtualHost *:443>

ServerName tvheadend.domain.com

ServerAlias ""

SSLEngine On

SSLCertificateFile /etc/apache2/ssl/apache.crt

SSLCertificateKeyFile /etc/apache2/ssl/apache.key

SSLProtocol +TLSv1.2

   

ProxyPreserveHost On

SSLProxyEngine On

ProxyRequests Off

RequestHeader set Front-End-Https "On"

   

<Location /> 

Order allow,deny

Allow from all

ProxyPass http://localhost:9981/

ProxyPassReverse http://localhost:9981/

</Location>


<Location /comet/ws>

Order allow,deny

Allow from all

ProxyPass ws://localhost:9981/comet/ws

ProxyPassReverse ws://localhost:9981/comet/ws


RewriteEngine on

RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]

RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]

RewriteRule .* ws://localhost:9981/comet/ws [P]

</Location>


</Virtualhost>


a2ensite tvheadend.conf


service apache2 restart


4.2 까지는 websocket 을 사용하지 않지만, 4.3 부터 websocket을 사용합니다. 그래서 찐하게 된 부분도 설정에 추가되어야 합니다.


4.3 버전에서 웹소켓 설정이 없으면, 그냥 위 아래 빠만 나오는 상황이 됩니다. 꼭 추가하세요.


한편, https 포트로 443을 못쓰시는 분들은 VirtualHost 설정에서 수정하시고 아래에서 추가적으로 Listen 8080 등의 리스닝 포트를 설정해주시길 바랍니다.


root@raspberrypi:/etc/apache2# cat ports.conf 

# If you just change the port or add more ports here, you will likely also

# have to change the VirtualHost statement in

# /etc/apache2/sites-enabled/000-default.conf


Listen 80


<IfModule ssl_module>

Listen 443

</IfModule>


<IfModule mod_gnutls.c>

Listen 443

</IfModule>






3. 테스트



앱에서 9982 는 http://domain.com:9982/ 로 넣어주시고 9981 은 https://tvheadend.domain.com/ 으로 넣어주시길 바랍니다.


감사합니다.




댓글