🤖 Ai回答: Setting up FRP (Fast Reverse Proxy) on a VPS (Virtual Private Server) allows you to securely expose local services (e.g., a web server, database, or desktop) to the internet or access them remotely through the VPS、Below is a step-by-step guide to configure FRP on a VPS and a local client.
1、What You Need
A VPS with a public IP address (e.g., from DigitalOcean, AWS, Vultr, or similar providers).
FRP installed on both the VPS (server) and your local machine (client).
Basic knowledge of Linux command-line tools (e.g., `wget`, `unzip`, `nano`).
2、Install FRP on the VPS (Server)
Step 1: Download FRP
bash
wget https://github.com/fatedier/frp/releases/download/v0.48.0/frp_0.48.0_linux_amd64.tar.gz
tar -zxvf frp_0.48.0_linux_amd64.tar.gz
cd frp_0.48.0
Step 2: Create Configuration File for the Server
Create a configuration file (e.g., `frps.ini`):
bash
nano frps.ini
Add the following content (adjust parameters as needed):
ini
[common]
bind_port = 7000 Port for incoming client connections
vhost_http_port = 80 Optional: For HTTP traffic via domain
dashboard_port = 7500 Optional: FRP dashboard for monitoring
dashboard_user = admin Username for dashboard
dashboard_pwd = admin123 Password for dashboard
token = your_secure_token Authentication token (required for client-server communication)
Step 3: Start the FRP Server
bash
nohup ./frps -c frps.ini &
Step 4: Configure Firewall (Optional)
Allow traffic on the FRP port (e.g., `7000`):
bash
sudo ufw allow 7000/tcp
sudo ufw reload
3、Install FRP on the Client Machine
Step 1: Download FRP (Same as VPS)
bash
wget https://github.com/fatedier/frp/releases/download/v0.48.0/frp_0.48.0_linux_amd64.tar.gz
tar -zxvf frp_0.48.0_linux_amd64.tar.gz
cd frp_0.48.0
Step 2: Create Configuration File for the Client
Create a configuration file (e.g., `frpc.ini`):
bash
nano frpc.ini
Add the following content:
ini
[common]
server_addr = your_vps_ip Public IP of your VPS
server_port = 7000 Port configured on the VPS (e.g., 7000)
token = your_secure_token Same token as the server
Example: Expose a local web server (e.g., running on port 80)
[web_server]
type = http
local_ip = 127.0.0.1
local_port = 80
custom_domains = yourdomain.com Optional: Use a domain instead of IP
Example: Expose a MySQL database (port 3306)
[mysql]
type = tcp
local_ip = 127.0.0.1
local_port = 3306
remote_port = 6033 Port on the VPS to access MySQL
4、Accessing Services via VPS
HTTP/HTTPS Service: Visit `http://your_vps_ip` or `http://yourdomain.com`.
TCP Service (e.g., MySQL): Connect to `your_vps_ip:6033` (replace `6033` with your `remote_port`).
5、Security Considerations
1、Use a Strong Token: Replace `your_secure_token` with a random string (e.g., generated via `openssl rand -hex 16`).
2、Restrict Ports: Use non-default ports (e.g., `7000` for FRP) and avoid exposing sensitive services on common ports.
3、SSL/TLS: For HTTP/HTTPS traffic, configure HTTPS on your local service or use `vhost_https_port` in FRP.
4、Firewall Rules: Allow only necessary ports on the VPS.
6、Troubleshooting
Check Logs:
Server logs: `./frps -c frps.ini` (run directly to see logs)、
Client logs: `./frpc -c frpc.ini`.
Verify Connectivity:
Ensure your VPS's firewall allows traffic on the FRP port (`7000` in this example).
Test Configuration:
Use `curl http://your_vps_ip` or `telnet your_vps_ip 6033` to test connections.
7、Use Cases
Remote Desktop: Expose a local desktop via RDP/SSH over FRP.
Development: Access a local development server (e.g., `localhost:3000`) from anywhere.
Database Access: Securely connect to a local database (MySQL, PostgreSQL) via the VPS.
Example: Exposing a Local Web Server
1、On the client machine, run a local web server (e.g., `python -m http.server 8000`).
2、Update `frpc.ini`:
ini
[web]
type = http
local_port = 8000
custom_domains = myweb.yourdomain.com
3、Access via `http://myweb.yourdomain.com` (if using a domain) or `http://your_vps_ip:your_remote_port`.
Let me know if you need help with a specific setup!