嘿哈布尔!
最近,我发现自己处于一种情况,需要在无法完全访问互联网的公司网络中工作,正如您从标题中可以猜到的那样,Telegram 被阻止了。 相信这种情况很多人都熟悉。
我可以不用即时通讯工具,但工作时我需要的是 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 配置中添加的内容:
- 我们更改根位置,这会将请求代理到端口 8000,Webogram 会在该端口上响应
- 我们使用 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 进行代理。
我希望本教程对我以外的其他人也有用。
非常感谢所有读到最后的人。
如果有人有任何困难或者我有任何不准确的地方,我很乐意在评论或私信中回答并尽力帮助你。
来源: habr.com