Docker+Nginx+FRP

0.云服务器需要打开的端口:7000、80
1.反代将来自80端口的HTTP请求转发至FRPS
2.FRPS和FRPC之间通过7000通讯
3.FRPC接收到转发过来的流量,转发至本地80端口

以上所有端口都可以通过docker、nginx、frpc各种组合配置
增加反代的目的是捕获请求源的IP

服务端

frps.ini:

cat > /etc/frps/frps.ini <<EOF
[common]
bind_port = 7000
token =e041a374-1489-4e42-8eb6-38a726fe6489
EOF

nginx default.conf:

cat > /etc/nginx/conf.d/default.conf <<EOF
server {
    listen 80;
    server_name "";

    location / {

         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header Host $host;
         proxy_redirect off;
         #proxy_bind $remote_addr transparent;
         client_max_body_size       1m;

         proxy_pass http://frps;

         error_log /dev/null;
         access_log off;
    }
}
EOF

docker:

docker network create -d bridge frp-net
docker run --restart=always -p 7000:7000 --network frp-net -d -v /etc/frp/frps.ini:/etc/frp/frps.ini --name frps snowdreamtech/frps
docker run --restart=always -p 80:80 --network frp-net -d -v /etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf --name nginx rsnow/nginx

客户端

https://github.com/fatedier/frp/releases/download/v0.39.1/frp_0.39.1_windows_amd64.zip

frpc.ini:

[common]
server_addr = {server.ip}
server_port = 7000
# console or real logFile path like ./frpc.log
log_file = ./frpc.log
# trace, debug, info, warn, error
log_level = warn
# auth token
token =e041a374-1489-4e42-8eb6-38a726fe6489

[www]
# tcp | udp | http | https | stcp | xtcp, default is tcp
type = tcp
local_ip = 127.0.0.1
local_port = 80
remote_port = 80
# limit bandwidth for this proxy, unit is KB and MB
bandwidth_limit = 1MB
# true or false, if true, messages between frps and frpc will be encrypted, default is false
use_encryption = true
# if true, message will be compressed
use_compression = true

声明

本文采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可,发表在CSDN博客园,欢迎读者转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接!请读者/爬虫们尊重版权

posted @ 2022-02-13 17:38  ChasingDreams  阅读(255)  评论(0编辑  收藏  举报