公网ip服务器
apt update
apt install wireguard
cd /etc/wireguard/
umask 077; wg genkey | tee privatekey_s | wg pubkey > publickey_s
umask 077; wg genkey | tee privatekey_192_168_1_8 | wg pubkey > publickey__192_168_1_8
vim /etc/sysctl.conf
#添加
net.ipv4.ip_forward = 1
#生效
sysctl -p
vim /etc/wireguard/wg0.conf
#添加 注:修改配置前先停止运行wg-quick down wg0
[Interface]
Address = 172.18.103.185/20
SaveConfig = true
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
ListenPort = 51820#privatekey_s
PrivateKey = cBSjtbk31HuCkXNJKTA4clRwTd+ojHlrhXNDmsDzymY=
[Peer]
PublicKey = bW4lJJMBDKJMU18i8Sly+cxi6aixptOXOLcnhhGfyzQ=
AllowedIPs = 192.168.1.9/32[Peer]
#publickey__192_168_1_8
PublicKey = Q6LDJppJKyOU/qO6Y9JJQnc/kS/cAqqu5TjEkHapKnI=
AllowedIPs = 192.168.1.8/32#启动
wg-quick up wg0
apt update
apt install nginx
vim /etc/nginx/sites-enabled/192_168_1_8
#添加
server { listen 8080; #有域名后改为80 server_name localhost; #有域名后改为域名 index index.html; location / { proxy_pass http://192.168.1.8:80/; } }service nginx restart
#安装同上不用生成秘钥
#配置如下
[Interface]
Address = 192.168.1.8/24
DNS = 192.168.1.1, 114.114.114.114
#privatekey_192_168_1_8
PrivateKey = EJE36sGBmwFOgBgXhE/9EQss2DkiGDbbozvcJHOL8ks=
#ListenPort = 51820
[Peer]
#publickey_s
PublicKey = sQ87BE5uQijxGrlP79wu4MHGRSe99qsKaQ+/YEv3M0s=
AllowedIPs = 172.18.103.185/32
#AllowedIPs = 0.0.0.0/0
Endpoint = 8.217.127.19:51820
#启动
wg-quick up wg0
#上线环境