How does frp configure multi-port intranet penetration? How to configure frp multi-port?

FRP intranet penetration application scenarios: local web service external network access, local development of WeChat, local joint debugging of Alipay\WeChat payment, TCP/UDP port forwarding

The website developed on this machine does not need to be uploaded to the server for customer testing. It can be easily solved by using FRP internal and external network penetration; WeChat development does not need to be uploaded to the server. Use the free FRP internal network penetration server to help you solve port 80 The problem is to realize the WeChat server directly accessing your local web service.

When using frp as internal network penetration, sometimes we need multiple ports to penetrate, how to configure it?

 

FRP Intranet Penetration Application Scenarios

Thinking:
We know that if frp wants to penetrate the intranet, it needs to configure the server and client. If you need to directly access port 80, you need to configure it in nginx. Then, let's configure in detail from these three aspects:

1. frp server configuration

Find the frps.ini configuration file on the server, and the configuration information is as follows:

[common]
#穿透监听端口与地址(0.0.0.0表示允许任何地址)
bind_addr = 0.0.0.0
bind_port = 7000
# 跟frpc通讯验证密钥
token = 可以自定义的token.如果需要的话请自行配置。如果不需要,可以注释掉
subdomain_host = 访问的域名。如果需要的话修改成自己的
#服务器用以显示连接状态的站点端口,以下配置中可以通过访问IP:7500登录查看frp服务端状态等信息
dashboard_addr = 0.0.0.0
dashboard_port = 7500
dashboard_user = 自定义的用户名
dashboard_pwd = 自定义的密码

#日志路径
log_file = /home/frp_0.46.1_linux_amd64/log/frps.log

#以下是配置多端口的
#端口8079是博客管理后台的项目
[tcp_blog-admin]
type = tcp
local_port = 8079
listen_port = 8079

#端口8080是博客前台项目访问地址
[tcp_blog]
type = tcp
local_port = 8080
listen_port = 8080

#端口8082是其他项目访问的
[tcp_app3]
type = tcp
local_port = 8082
listen_port = 8082

After the configuration is complete, if frp is configured to start randomly. You can directly execute the following command to restart frp

systemctl restart frps

Extension: "Frp server runs in the background under Centos7 and boots up automatically (Frp client is the same)". You can refer to: Search [ frp ] keywords in Kaige's personal blog This article

Two, Nginx configuration

Add the following configuration to the Nginx configuration file:

# 端口8080映射到80端口
server {
    listen 80;
    server_name blog.xxx.com;

    location / {
        resolver 8.8.8.8;
        proxy_pass http://$host:8080;
        proxy_redirect off;
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 90;
        proxy_read_timeout 90;
        proxy_buffer_size 6k;
        proxy_buffers 6 128k;
        proxy_busy_buffers_size 256k;
        proxy_temp_file_write_size 256k;

        proxy_set_header Host $http_host;
    }

    location ~ .*\.(gif|jpg|png|bmp|swf|css|js)$ {
        proxy_pass http://$host:8080;
        expires 30d;
    }

    location ~ .*\.(js|css)?$ {
        expires 1d;
    }
}

# 端口8079映射到80端口
server {
    listen 80;
    server_name blog-admin.mmmm.com;

    location / {
        proxy_pass http://127.0.0.1:8079;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ~ .*\.(gif|jpg|png|bmp|swf|css|js)$ {
        proxy_pass http://$host:8079;
        expires 30d;
    }
    location ~ .*\.(js|css)?$ {
        expires 1d;
    }
}

# 端口8082映射到80端口
server {
    listen 80;
    server_name app3.nnn.com
    .com;

    location / {
        proxy_pass http://127.0.0.1:8082;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ~ .*\.(gif|jpg|png|bmp|swf|css|js)$ {
        proxy_pass http://$host:8082;
        expires 30d;
    }
    location ~ .*\.(js|css)?$ {
        expires 1d;
    }
}

Note: server_name cannot be configured the same. If the configuration is the same, when the following restart command is executed, a failure will be prompted

After configuring Nginx, you need to restart Nginx. Restart command:

/usr/local/nginx/sbin/nginx -s reload

3. frpc.ini configuration

After configuring the frp server and Nginx, let's configure the frp client now

[common]
server_addr = frp服务端所服务器所在的ip
server_port = 7000
token = 这里的token必须和frps.ini里面配置的一致

# 配置8079端口
[tcp_blog-admin]
type = tcp
local_ip = 127.0.0.1
local_port = 8079
remote_port = 8079
custom_domains = blog-admin.xxx.com

# 配置8080端口
[tcp_blog]
type = tcp
local_ip = 127.0.0.1
local_port = 8080
remote_port = 8080
custom_domains = blog.mmmm.com

# 配置8082端口
[tcp_app3]
type = tcp
local_ip = 127.0.0.1
local_port = 8082
remote_port = 8082
custom_domains = app3.nnn.com

Note: custom_domains cannot be configured the same. If the configuration is the same, an error message will be prompted when restarting the frp client.

After the configuration is complete, restart the frp client. You can see that as shown in the figure, it means that the frp multi-port configuration has been successful.

 

Example diagram of successful frp client startup

If you are still worried, you can log in to the frp management page to check.

The frp management page is to configure 7500-related user names and passwords in frps.ini.

The access address is the ip:7500 of the frp server. Then enter the user name and password, you can access. Under the Proxies menu, click TCP to see the corresponding port. As shown below:

 

The frp management interface checks the three different ports started

Guess you like

Origin blog.csdn.net/kaizi_1992/article/details/131268240