ํค์ด ํ๋ธ๋ฅด!
์ต๊ทผ์ ์ ๋ ์ธํฐ๋ท์ ๋ํ ๋ถ์์ ํ ์ก์ธ์ค๊ฐ ์๋ ๊ธฐ์ ๋คํธ์ํฌ ๋ด๋ถ์์ ์์ ํด์ผ ํ๋ ์ํฉ์ ์ฒํด ์์๊ณ ์ ๋ชฉ์์ ์ง์ํ ์ ์๋ฏ์ด Telegram์ด ์ฐจ๋จ๋์์ต๋๋ค. ๋๋ ์ด ์ํฉ์ด ๋ง์ ์ฌ๋๋ค์๊ฒ ์น์ํ๋ค๊ณ ํ์ ํฉ๋๋ค.
์ธ์คํดํธ ๋ฉ์ ์ ์์ด๋ ํ ์ ์์ง๋ง ์
๋ฌด์ ํ์ํ ๊ฒ์ ํ
๋ ๊ทธ๋จ์ด์์ต๋๋ค. ์
๋ฌด์ฉ ์ปดํจํฐ์ ํด๋ผ์ด์ธํธ๋ฅผ ์ค์นํ๋ ๊ฒ๋ ๋ถ๊ฐ๋ฅํ๊ณ , ๊ฐ์ธ ๋
ธํธ๋ถ์ ์ฌ์ฉํ๋ ๊ฒ๋ ๋ถ๊ฐ๋ฅํ์ต๋๋ค. ๋ ๋ค๋ฅธ ํด๊ฒฐ์ฑ
์ ๊ทธ๊ฒ์ ์ฌ์ฉํ๋ ๊ฒ ๊ฐ์ต๋๋ค
๋คํ์ค๋ฝ๊ฒ๋ Webogram์ ์์ค ์ฝ๋๋ฅผ ๋ค์์์ ์ฌ์ฉํ ์ ์๋ ์คํ ์์ค ํ๋ก์ ํธ์
๋๋ค.
์ค์น ๋ฐ ์คํ ์์ฒด๋ ์ด๋ ต์ง ์์ง๋ง Telegram ์๋ฒ์ ๋ํ ์ก์ธ์ค๊ฐ ์ฐจ๋จ๋ ๋คํธ์ํฌ ๋ด์์ ์๋ํ๋ ์กฐ๊ฑด์์๋ ์น ๋ฒ์ ์ด ์ฌ์ฉ์ ์ปดํจํฐ์์ Telegram ์๋ฒ๋ก ์์ฒญ์ ๋ณด๋ด๊ธฐ ๋๋ฌธ์ ์ฑ๊ณต๋ณด๋ค ์ค๋งํ ๊ฐ๋ฅ์ฑ์ด ๋ ๋์ต๋๋ค.
์ด ์ข๊ฒ๋ ์ด๋ ๋งค์ฐ ๊ฐ๋จํ์ง๋ง ๋ช
ํํ์ง๋ ์์ ์์ ์ฌํญ์
๋๋ค. ๋๋ ์ด ์๋ฃจ์
์ ์์ฑ์๊ฐ ์๋์ ๊ฒฝ๊ณ ํ๊ณ ์ถ์ต๋๋ค. ๋๋ ๊ทธ๊ฒ์ ์ฐพ์ ์ ์์๋ค
์ปท ์๋์๋ Webogram ๋ฏธ๋ฌ์ ๋จ๊ณ๋ณ ์ค์ ๊ณผ nginx๋ฅผ ์ฌ์ฉํ์ฌ Telegram ์๋ฒ์ ์์ฒญ์ ํ๋ก์ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ด ๋์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด, ์๋ก ์ค์น๋๊ณ ์
๋ฐ์ดํธ๋ Ubuntu Server 18.04.3์ ์ ํํ์ต๋๋ค.
์ฐธ๊ณ : ์ด ํํ ๋ฆฌ์ผ์๋ nginx์์ ๋๋ฉ์ธ์ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์ง์นจ์ด ํฌํจ๋์ด ์์ง ์์ต๋๋ค. ์ด ์์ ์ ์ง์ ์ํํด์ผ ํฉ๋๋ค. ์ด ํํ ๋ฆฌ์ผ์์๋ SSL์ ์ฌ์ฉํ์ฌ ๋๋ฉ์ธ์ ์ด๋ฏธ ๊ตฌ์ฑํ์ผ๋ฉฐ ์ด๋ฅผ ๊ตฌ์ฑํ๋ ค๋ ์๋ฒ ์์ฒด๊ฐ ์ํ๋ ๋ฐฉ์์ผ๋ก Telegram ์๋ฒ์ ์ก์ธ์คํ ์ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
์ด ์๋ฒ์ IP๊ฐ 10.23.0.3์ด๊ณ ๋๋ฉ์ธ ์ด๋ฆ์ด mywebogram.localhost๋ผ๊ณ ๊ฐ์ ํฉ๋๋ค.
์ด๋ฌํ ๊ท์น์ ๋ฐํ์ผ๋ก ๊ตฌ์ฑ์ ์๋ฅผ ์ ์ํ๊ฒ ์ต๋๋ค. ๊ฐ์ ์์ ์ ๊ฒ์ผ๋ก ๋ณ๊ฒฝํ๋ ๊ฒ์ ์์ง ๋ง์ญ์์ค.
์, ์์ํ๊ฒ ์ต๋๋ค.
Webogram์ ์คํํ๋ ค๋ฉด nodejs๊ฐ ํ์ํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก Ubuntu ๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ค์นํ๋ฉด nodejs ๋ฒ์ 8.x๋ฅผ ์ป๊ฒ ๋ฉ๋๋ค. 12.x๊ฐ ํ์ํฉ๋๋ค.
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt update && sudo apt -y install nodejs
์ฐ๋ฆฌ๋ ์น๊ทธ๋จ์ ๊ธฐ๋ฐ์ด ๋ ์ฅ์๋ฅผ ์ ํํฉ๋๋ค.
์๋ฅผ ๋ค์ด ํ ๋๋ ํฐ๋ฆฌ์ ๋ฃจํธ์ ๋ฐฐ์นํด ๋ณด๊ฒ ์ต๋๋ค. ์ด๋ ๊ฒ ํ๋ ค๋ฉด ๊ณต์ ์ ์ฅ์๋ฅผ ์๋ฒ์ ๋ณต์ ํ์ธ์.
cd ~ && git clone https://github.com/zhukov/webogram.git
๋ค์ ๋จ๊ณ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ๋ ๋ฐ ํ์ํ ๋ชจ๋ ์ข ์์ฑ์ ์ค์นํ๋ ๊ฒ์ ๋๋ค.
cd webogram && npm install
ํ ์คํธ ์คํ์ ํด๋ณด์. ๋ค์ ๋ช ๋ น์ ์คํํ์ญ์์ค.
npm start
๊ทธ ํ ๋ธ๋ผ์ฐ์ ์์ ์ด๋ ค๊ณ ํฉ๋๋ค.
http://10.23.0.3:8000/app/index.html
์ง๊ธ๊น์ง ๋ชจ๋ ์์ ์ ์ฌ๋ฐ๋ฅด๊ฒ ์ํํ๋ค๋ฉด Webogram ์ธ์ฆ ํ์ด์ง๊ฐ ์ด๋ฆฝ๋๋ค.
์ด์ ์๋น์ค๋ก ์คํ๋๋๋ก ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์ฑํด์ผ ํฉ๋๋ค. ์ด๋ฅผ ์ํด ํ์ผ์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
sudo touch /lib/systemd/system/webogram.service
์๋ฌด ํธ์ง๊ธฐ์์๋ ์ด๊ณ ๋ค์๊ณผ ๊ฐ์ด ํ์ํฉ๋๋ค(WorkDirectory ๊ฒฝ๋ก ์ ๋ ฅ).
[Unit]
Description=Webogram mirror
[Service]
WorkingDirectory=/home/tg/webogram
ExecStart=/usr/bin/npm start
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
๊ทธ๋ฐ ๋ค์ ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค.
๋ณ๊ฒฝ ์ฌํญ ์ ์ฉ
sudo systemctl daemon-reload
์๋ ์คํ ํ์ฑํ:
sudo systemctl enable webogram.service
์๋น์ค๋ฅผ ์์ํด ๋ณด๊ฒ ์ต๋๋ค.
sudo systemctl start webogram.service
๋จ๊ณ๋ฅผ ์๋ฃํ ํ์๋ Webogram์ ํฌํธ 8000์์ ๊ณ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
nginx๋ฅผ ํตํด Webogram์ ๋ํ ์ก์ธ์ค๋ฅผ ์ค์ ํ๋ฏ๋ก ์ธ๋ถ ์์ฒญ์ ๋ํด ํฌํธ 8000์ ๋ซ์ต๋๋ค.
์ด๋ฅผ ์ํด(๋๋ ๊ทํ์๊ฒ ํธ๋ฆฌํ ๋ค๋ฅธ ๋ฐฉ๋ฒ) udf ์ ํธ๋ฆฌํฐ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
sudo ufw deny 8000
์ฌ์ ํ udf๋ฅผ ์ฌ์ฉํ๊ธฐ๋ก ๊ฒฐ์ ํ์ง๋ง ์๋ฒ์์ ๋นํ์ฑํ๋ ๊ฒฝ์ฐ ๊ท์น์ ๋ ์ถ๊ฐํ๊ณ (๋ชจ๋ ๊ฒ์ด ๋ฌด๋์ง์ง ์๋๋ก) udf๋ฅผ ํ์ฑํํฉ๋๋ค.
sudo ufw allow ssh
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable
๋ค์์ผ๋ก nginx ๊ตฌ์ฑ ๋ณ๊ฒฝ์ ์์ํ๊ฒ ์ต๋๋ค.
์์์ ๊ฒฝ๊ณ ํ๋ฏ์ด SSL์ด ํฌํจ๋ ๋๋ฉ์ธ์ด ์ด๋ฏธ ์๋ฒ์ ๊ตฌ์ฑ๋์ด ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค. ๋๋ฉ์ธ ๊ตฌ์ฑ ํ์ผ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์๋ํ๋ ค๋ฉด ๋ฌด์์ด ์ถ๊ฐ๋์ด์ผ ํ๋์ง์๋ง ์ฃผ์๋ฅผ ๊ธฐ์ธ์ด๊ฒ ์ต๋๋ค.
server {
...
location ^~ /pluto/apiw1/ {
proxy_pass https://pluto.web.telegram.org/apiw1/;
}
location ^~ /venus/apiw1/ {
proxy_pass https://venus.web.telegram.org/apiw1/;
}
location ^~ /aurora/apiw1/ {
proxy_pass https://aurora.web.telegram.org/apiw1/;
}
location ^~ /vesta/apiw1/ {
proxy_pass https://vesta.web.telegram.org/apiw1/;
}
location ^~ /flora/apiw1/ {
proxy_pass https://flora.web.telegram.org/apiw1/;
}
location ^~ /pluto-1/apiw1/ {
proxy_pass https://pluto-1.web.telegram.org/apiw1/;
}
location ^~ /venus-1/apiw1/ {
proxy_pass https://venus-1.web.telegram.org/apiw1/;
}
location ^~ /aurora-1/apiw1/ {
proxy_pass https://aurora-1.web.telegram.org/apiw1/;
}
location ^~ /vesta-1/apiw1/ {
proxy_pass https://vesta-1.web.telegram.org/apiw1/;
}
location ^~ /flora-1/apiw1/ {
proxy_pass https://flora-1.web.telegram.org/apiw1/;
}
location ^~ /DC1/ {
proxy_pass http://149.154.175.10:80/;
}
location ^~ /DC2/ {
proxy_pass http://149.154.167.40:80/;
}
location ^~ /DC3/ {
proxy_pass http://149.154.175.117:80/;
}
location ^~ /DC4/ {
proxy_pass http://149.154.175.50:80/;
}
location ^~ /DC5/ {
proxy_pass http://149.154.167.51:80/;
}
location ^~ /DC6/ {
proxy_pass http://149.154.175.100:80/;
}
location ^~ /DC7/ {
proxy_pass http://149.154.167.91:80/;
}
location ^~ /DC8/ {
proxy_pass http://149.154.171.5:80/;
}
location / {
auth_basic "tg";
auth_basic_user_file /etc/nginx/passwd.htpasswd;
proxy_pass http://localhost:8000/;
proxy_read_timeout 90s;
proxy_connect_timeout 90s;
proxy_send_timeout 90s;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
nginx ๊ตฌ์ฑ์ ์ถ๊ฐํ๋ ๊ฒ:
- Webogram์ด ์๋ตํ๋ ํฌํธ 8000์ผ๋ก ์์ฒญ์ ํ๋ก์ํ๋ ๋ฃจํธ ์์น๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค.
- basic-auth๋ฅผ ์ฌ์ฉํ์ฌ ๋ฃจํธ ์์น๋ฅผ ๋ซ์ต๋๋ค. ์ด๋ ์ฟ๋ณด๋ ๋๊ณผ ๋ด์ผ๋ก๋ถํฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ข ๋ฃํ๋ ์์ ํ ์์ง์ ์ธ ๋จ๊ณ์ ๋๋ค. (๋ํ ์ฐจ๋จ ๋ฌธ์ ๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด)
- Telegram ์๋ฒ์ Proxy_path๊ฐ ์๋ ์ฌ๋ฌ ์์น๋ ์ ํํ ์ฐ๋ฆฌ๊ฐ ์์ฒญ์ ํ๋ก์ํ ์๋ํฌ์ธํธ์ ๋๋ค.
๊ทธ๋ฆฌ๊ณ ํ์ผ์ ๋ง๋ค์ด๋ณด์ /etc/nginx/passwd.htpasswd;
nginx์๋ ์ฌ์ฉ์ ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํ ์ ์๋ ๊ฒ์ด ์์ต๋๋ค.
sudo apt install apache2-utils
sudo htpasswd -c /etc/nginx/passwd.htpasswd tg
nginx๋ฅผ ๋ค์ ์์ํฉ๋๋ค:
sudo systemctl restart nginx
์ด์ Webogram์ ๋ค์์์๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋จ์ ๊ฒ์ด ๊ฑฐ์ ์์ต๋๋ค. ํ๋ก์ ํธ ์์ฒด๋ฅผ ์ฝ๊ฐ ๋ณ๊ฒฝํ๊ฒ ์ต๋๋ค.
ํธ์ง๊ธฐ์์ ํ์ผ ์ด๊ธฐ ~/webogram/app/js/lib/mtproto.js
๊ทธ๋ฆฌ๊ณ ์์์ ๋ค์ ํ์์ผ๋ก ๊ฐ์ ธ์ต๋๋ค.
/*!
* Webogram v0.7.0 - messaging web application for MTProto
* https://github.com/zhukov/webogram
* Copyright (C) 2014 Igor Zhukov <[email protected]>
* https://github.com/zhukov/webogram/blob/master/LICENSE
*/
angular.module('izhukov.mtproto', ['izhukov.utils'])
.factory('MtpDcConfigurator', function () {
var sslSubdomains = ['pluto', 'venus', 'aurora', 'vesta', 'flora']
var dcOptions = Config.Modes.test
? [
{id: 1, host: 'mywebogram.localhost/DC1', port: 80},
{id: 2, host: 'mywebogram.localhost/DC2', port: 80},
{id: 3, host: 'mywebogram.localhost/DC3', port: 80}
]
: [
{id: 1, host: 'mywebogram.localhost/DC4', port: 80},
{id: 2, host: 'mywebogram.localhost/DC5', port: 80},
{id: 3, host: 'mywebogram.localhost/DC6', port: 80},
{id: 4, host: 'mywebogram.localhost/DC7', port: 80},
{id: 5, host: 'mywebogram.localhost/DC8', port: 80}
]
var chosenServers = {}
function chooseServer (dcID, upload) {
if (chosenServers[dcID] === undefined) {
var chosenServer = false,
i, dcOption
if (Config.Modes.ssl || !Config.Modes.http) {
var subdomain = sslSubdomains[dcID - 1] + (upload ? '-1' : '')
var path = Config.Modes.test ? 'apiw_test1' : '/apiw1/'
chosenServer = 'https://mywebogram.localhost/' + subdomain + path
return chosenServer
}
for (i = 0; i < dcOptions.length; i++) {
dcOption = dcOptions[i]
if (dcOption.id == dcID) {
chosenServer = 'http://' + dcOption.host + '/apiw1'
break
}
}
chosenServers[dcID] = chosenServer
}
...
๊ทธ๋ฐ ๋ค์ ๋ธ๋ผ์ฐ์ ์์ ์ ํ๋ฆฌ์ผ์ด์ ํ์ด์ง๋ฅผ ์๋ก ๊ณ ์ณ์ผ ํฉ๋๋ค.
๋ธ๋ผ์ฐ์ ์ฝ์์ ์ด๊ณ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋คํธ์ํฌ ์์ฒญ์ ์ดํด๋ณด์ธ์. ๋ชจ๋ ๊ฒ์ด ์๋ํ๊ณ XHR ์์ฒญ์ด ์๋ฒ๋ก ์ด๋ํ๋ฉด ๋ชจ๋ ๊ฒ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์๋ฃ๋ ๊ฒ์ด๋ฉฐ Webogram์ ์ด์ nginx๋ฅผ ํตํด ํ๋ก์๋ฉ๋๋ค.
์ด ํํ ๋ฆฌ์ผ์ด ์ ์ธ์ ๋ค๋ฅธ ๋๊ตฐ๊ฐ์๊ฒ๋ ๋์์ด ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
๋๊น์ง ์ฝ์ด์ฃผ์ ๋ชจ๋ ๋ถ๋ค๊ป ์ง์ฌ์ผ๋ก ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
ํน์ ์ด๋ ค์์ด ์์ผ์ ๋ถ์ด๋ ์ ๊ฐ ๋ถ์ ํํ ๋ด์ฉ์ ์์ฑํ์ ๊ฒฝ์ฐ ๋๊ธ์ด๋ PM์ ํตํด ๊ธฐ๊บผ์ด ๋ต๋ณํด ๋๋ฆฌ๊ณ ๋์์ ๋๋ฆด ์ ์๋๋ก ๋
ธ๋ ฅํ๊ฒ ์ต๋๋ค.
์ถ์ฒ : habr.com