Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
【教程】利用nghttpx使squid3支持HTTP/2
deepin Talks
3035
views ·
4
replies ·
To
floor
Go
u855697021
deepin
2016-03-15 17:42
Author
本帖最后由 u855697021 于 2016-3-15 09:56 编辑
利用nghttpx使squid3支持HTTP/2,实现加密代理访问。(话只能说到这份上了)
首先,任何SSL连接都需要一个域名,所以需要设法申请一个。
不想花钱的可以申.tk等免费域名,想花钱更安稳些的,godaddy神马的都可以。
步骤:(服务器端,以Debian为例)
1. 下载Let's Encrypt Client:
git clone https://github.com/letsencrypt/letsencrypt
Copy the Code
2. 为你的域名申请SSL证书(或者可以使用已有的证书):(注意在执行这一步前,确保你申请的域名指向了当前服务器的IP地址)
cd letsencrypt
sudo ./letsencrypt-auto certonly --standalone --email [你的邮箱] -d [你的域名] --agree-tos
Copy the Code
(如果服务器同时正在运行网站的话,则需要用webroot方式验证,
这种情况请参阅Let's Encrypt文档:
https://letsencrypt.readthedocs.org/en/latest/
)
证书颁发后,客户端会显示证书保存的位置,记下文件夹的路径。
3. 安装squid3与nghttp2:
sudo apt-get install squid3 nghttp2
Copy the Code
(如果debian源未收录nghttp2的话,则需要从
https://nghttp2.org/
下载安装包)
4. 配置squid3(即编辑/etc/squid3/squid.conf),这个是我个人的配置:
# [HTTP2 Proxy Backend]
http_access allow localhost
http_port 127.0.0.1:8000
# No cache and log
cache deny all
access_log none
# Prefer IPv4 sites
dns_v4_first on
# No via header
via off
# No x-forwarded-for header
forwarded_for delete
Copy the Code
5. 建立文件/etc/nghttpx/nghttpx.conf,写入配置如下:
frontend=*,1443(需要在其它端口上运行的请自行修改)
backend=127.0.0.1,8000
private-key-file=[证书文件夹路径]/privkey.pem
certificate-file=[证书文件夹路径]/fullchain.pem
http2-proxy=yes
tls-proto-list=TLSv1.2
Copy the Code
6. 运行squid3,启动squid服务。
7. 运行nohup nghttpx >/dev/null 2>&1 &,启动nghttpx服务。
(客户端,需要使用Chrome或Opera访问该代理服务)
1. 下载Proxy SwitchyOmega:
https://github.com/FelisCatus/Sw ... 17/SwitchyOmega.crx
2. 打开chrome://extensions或者opera://extensions,将下载的插件拖进去。(注意不能直接双击安装,这是Chrome等的限制)
3. 点击SwitchyOmega图标,进入选项页面,编辑代理设置。
新建一个代理,代理方式为HTTPS,服务器地址为你的域名,端口为你指定的端口(这里是1443),然后注意保存设置。
4. 点击SwitchyOmega图标,切换到刚才创建的代理,即可使用指定代理上网。
注意:
1. 每三个月需要更新一次Let's Encrypt的证书,不然Chrome可能提示证书无效。
2. Chrome 45(或者使用45版Chrome内核的浏览器)无法使用此方法,这是45版内核的bug所致。这种情况下请更新或更换浏览器。
Reply
Like 0
Favorite
View the author
All Replies
u855697021
deepin
2016-03-16 01:55
#1
自顶帖...
Reply
Like 0
View the author
176******20
deepin
2016-03-16 02:36
#2
看起来很高深的样子
Reply
Like 0
View the author
joyk3000
deepin
2016-03-17 14:16
#3
不错,学习了
Reply
Like 0
View the author
u855697021
deepin
2016-03-27 21:28
#4
这几天为了让nghttpx能够随时启停和开机启动,写了一个服务脚本如下:
#! /bin/sh
### BEGIN INIT INFO
# Provides: nghttpx
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Nghttpx HTTP/2 proxy daemon
# Description: Nghttpx HTTP/2 proxy daemon
### END INIT INFO
# Path
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# Variables
proc=nghttpx
srv_name=${proc}
rt_dir=/tmp/proxy
user=nobody
pid_file=${rt_dir}/${proc}.pid
# Start service
start() {
_status
if [ $? -eq 0 ]; then
return 0
fi
# Run daemon process
mkdir -p $rt_dir
nohup nghttpx --pid-file=$pid_file --user=$user >/dev/null 2>&1 &
}
# Stop service
stop() {
_status
if [ $? -ne 0 ]; then
return 0
fi
# Kill daemon process
kill $(cat $pid_file)
rm $pid_file
}
# Restart service
restart() {
stop
start
}
# Check status (Internal function)
_status() {
if [ -e $pid_file ]; then
if ps $(cat $pid_file) >/dev/null 2>&1; then
return 0
fi
fi
return 1
}
# Check status
status() {
_status
if [ $? -eq 0 ]; then
echo "Service $srv_name running."
exit 0
else
echo "Service $srv_name not running."
exit 1
fi
}
# Service operations
case $1 in
start|stop|restart|status)
$1;;
# Show usage
*)
echo "Usage: $0 {start|stop|status|restart}";;
esac
Copy the Code
把以上脚本写入/etc/init.d/nghttpx,
然后用update-rc.d或者chkconfig加入到开机启动项中就可以实现HTTP/2代理开机自启动了。
(貌似Squid也需要写一个服务脚本wrap一下,不过方法应该是类似的)
Reply
Like 0
View the author
Please
sign
in first
Featured Collection
Change
Nuntia - Modern IMAP/SMTP mail client for Deepin (Beta tester wanted!)
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
Adding a Dancing Spectrum Bar to the Deepin Taskbar | deepin-spectrum
Popular Events
More
利用nghttpx使squid3支持HTTP/2,实现加密代理访问。(话只能说到这份上了)
首先,任何SSL连接都需要一个域名,所以需要设法申请一个。
不想花钱的可以申.tk等免费域名,想花钱更安稳些的,godaddy神马的都可以。
步骤:(服务器端,以Debian为例)
1. 下载Let's Encrypt Client:
2. 为你的域名申请SSL证书(或者可以使用已有的证书):(注意在执行这一步前,确保你申请的域名指向了当前服务器的IP地址)
这种情况请参阅Let's Encrypt文档:https://letsencrypt.readthedocs.org/en/latest/)
证书颁发后,客户端会显示证书保存的位置,记下文件夹的路径。
3. 安装squid3与nghttp2:
4. 配置squid3(即编辑/etc/squid3/squid.conf),这个是我个人的配置:
7. 运行nohup nghttpx >/dev/null 2>&1 &,启动nghttpx服务。
(客户端,需要使用Chrome或Opera访问该代理服务)
1. 下载Proxy SwitchyOmega:https://github.com/FelisCatus/Sw ... 17/SwitchyOmega.crx
2. 打开chrome://extensions或者opera://extensions,将下载的插件拖进去。(注意不能直接双击安装,这是Chrome等的限制)
3. 点击SwitchyOmega图标,进入选项页面,编辑代理设置。
新建一个代理,代理方式为HTTPS,服务器地址为你的域名,端口为你指定的端口(这里是1443),然后注意保存设置。
4. 点击SwitchyOmega图标,切换到刚才创建的代理,即可使用指定代理上网。
注意:
1. 每三个月需要更新一次Let's Encrypt的证书,不然Chrome可能提示证书无效。
2. Chrome 45(或者使用45版Chrome内核的浏览器)无法使用此方法,这是45版内核的bug所致。这种情况下请更新或更换浏览器。