반응형
하나의 서버가 http와 ws스펙을 지원해야 하고, apache / nginx 같은 웹서버 뒷단(Proxy 환경)에서 서비스를 해야 되는 경우가 생겼다.
nginx같은 경우 간단하게 헤더 몇개만 추가해주면 자연스럽게 해결이 되는데,
apache같은 경우는 rewrite engine과 proxy_wstunnel engine을 enable 시킨 후, 별도의 조건까지 등록을 해주어야 가능하다.
아래 커맨드는 Ubuntu / Debian 계열 Linux 기준의 예제이고, 위에 얘기한 engine들을 enable 시키는 방법은 아래와 같다.
$ a2enmod rewrite # 보통 default로 enable 되어있는 경우가 많다. $ a2enmod proxy_wstunnel
이제 Rewrite Engine 설정을 해준다. (포트가 6050인 경우)
# http-vhosts.conf
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} =websocket [NC]
RewriteRule .* ws://127.0.0.1:6050/$1 [P,L]
ProxyPass / http://127.0.0.1:6050
ProxyPassReverse / http://127.0.0.1:6050
모든 작업 후 apache2를 재시작 해주면 적용된다.
정리하는 김에.. Nginx같은 경우는 아래와 같이 설정하면 됨.
server:
location /:
proxy_pass http://127.0.0.1:6050;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
반응형
'개발 > Linux, System' 카테고리의 다른 글
| [Ubuntu 16.04] systemctl insserv: warning: script missing LSB tags and overrides (0) | 2017.10.25 |
|---|---|
| [Apache2] (22)Invalid argument: Couldn't set permissions on cross-process lock; check User and Group directives (0) | 2017.09.18 |
| [SSH] sshd_config maxsessions (0) | 2017.04.25 |
| [CentOS] overcommit_memory (0) | 2017.01.16 |
| [Linux] cp 명령어 overwrite (0) | 2016.07.12 |