Skip to content

Commit

Permalink
Merge pull request fatedier#801 from fatedier/dev
Browse files Browse the repository at this point in the history
bump version v0.20.0
  • Loading branch information
fatedier authored May 31, 2018
2 parents da78e3f + aeb9f2b commit 629f285
Show file tree
Hide file tree
Showing 70 changed files with 5,758 additions and 3,338 deletions.
28 changes: 17 additions & 11 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
name = "github.com/hashicorp/yamux"
revision = "2658be15c5f05e76244154714161f17e3e77de2e"

[[constraint]]
name = "github.com/gorilla/mux"
version = "1.6.2"

[[constraint]]
name = "github.com/rakyll/statik"
version = "0.1.0"
Expand All @@ -59,12 +63,16 @@

[[constraint]]
name = "github.com/spf13/cobra"
version = "0.0.2"
version = "0.0.3"

[[constraint]]
name = "github.com/vaughan0/go-ini"
revision = "a98ad7ee00ec53921f08832bc06ecf7fd600e6a1"

[[override]]
name = "github.com/templexxx/reedsolomon"
version = "0.1.1"

[prune]
go-tests = true
unused-packages = true
2 changes: 2 additions & 0 deletions Makefile.cross-compiles
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ app:
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_amd64 ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_arm ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "$(LDFLAGS)" -o ./frps_linux_arm ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_arm64 ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_arm64 ./cmd/frps
env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frpc_windows_386.exe ./cmd/frpc
env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frps_windows_386.exe ./cmd/frps
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frpc_windows_amd64.exe ./cmd/frpc
Expand Down
52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ frp is a fast reverse proxy to help you expose a local server behind a NAT or fi
* [TCP Stream Multiplexing](#tcp-stream-multiplexing)
* [Support KCP Protocol](#support-kcp-protocol)
* [Connection Pool](#connection-pool)
* [Load balancing](#load-balancing)
* [Rewriting the Host Header](#rewriting-the-host-header)
* [Set Headers In HTTP Request](#set-headers-in-http-request)
* [Get Real IP](#get-real-ip)
* [Password protecting your web service](#password-protecting-your-web-service)
* [Custom subdomain names](#custom-subdomain-names)
Expand Down Expand Up @@ -483,9 +485,50 @@ This feature is fit for a large number of short connections.
pool_count = 1
```

### Load balancing

Load balancing is supported by `group`.
This feature is available only for type `tcp` now.

```ini
# frpc.ini
[test1]
type = tcp
local_port = 8080
remote_port = 80
group = web
group_key = 123

[test2]
type = tcp
local_port = 8081
remote_port = 80
group = web
group_key = 123
```

`group_key` is used for authentication.

Proxies in same group will accept connections from port 80 randomly.

### Rewriting the Host Header

When forwarding to a local port, frp does not modify the tunneled HTTP requests at all, they are copied to your server byte-for-byte as they are received. Some application servers use the Host header for determining which development site to display. For this reason, frp can rewrite your requests with a modified Host header. Use the `host_header_rewrite` switch to rewrite incoming HTTP requests.
When forwarding to a local port, frp does not modify the tunneled HTTP requests at all, they are copied to your server byte-for-byte as they are received. Some application servers use the Host header for determining which development site to display. For this reason, frp can rewrite your requests with a modified host header. Use the `host_header_rewrite` switch to rewrite incoming HTTP requests.

```ini
# frpc.ini
[web]
type = http
local_port = 80
custom_domains = test.yourdomain.com
host_header_rewrite = dev.yourdomain.com
```

If `host_header_rewrite` is specified, the host header will be rewritten to match the hostname portion of the forwarding address.

### Set Headers In HTTP Request

You can set headers for proxy which type is `http`.

```ini
# frpc.ini
Expand All @@ -494,9 +537,11 @@ type = http
local_port = 80
custom_domains = test.yourdomain.com
host_header_rewrite = dev.yourdomain.com
header_X-From-Where = frp
```

If `host_header_rewrite` is specified, the Host header will be rewritten to match the hostname portion of the forwarding address.
Note that params which have prefix `header_` will be added to http request headers.
In this example, it will set header `X-From-Where: frp` to http request.

### Get Real IP

Expand Down Expand Up @@ -598,7 +643,7 @@ local_port = 6000-6006,6007
remote_port = 6000-6006,6007
```

frpc will generate 6 proxies like `test_tcp_0, test_tcp_1 ... test_tcp_5`.
frpc will generate 8 proxies like `test_tcp_0, test_tcp_1 ... test_tcp_7`.

### Plugin

Expand Down Expand Up @@ -626,7 +671,6 @@ plugin_http_passwd = abc

* Log http request information in frps.
* Direct reverse proxy, like haproxy.
* Load balance to different service in frpc.
* kubernetes ingress support.

## Contributing
Expand Down
47 changes: 45 additions & 2 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp
* [TCP 多路复用](#tcp-多路复用)
* [底层通信可选 kcp 协议](#底层通信可选-kcp-协议)
* [连接池](#连接池)
* [负载均衡](#负载均衡)
* [修改 Host Header](#修改-host-header)
* [设置 HTTP 请求的 header](#设置-http-请求的-header)
* [获取用户真实 IP](#获取用户真实-ip)
* [通过密码保护你的 web 服务](#通过密码保护你的-web-服务)
* [自定义二级域名](#自定义二级域名)
Expand Down Expand Up @@ -510,6 +512,32 @@ tcp_mux = false
pool_count = 1
```

### 负载均衡

可以将多个相同类型的 proxy 加入到同一个 group 中,从而实现负载均衡的功能。
目前只支持 tcp 类型的 proxy。

```ini
# fprc.ini
[test1]
type = tcp
local_port = 8080
remote_port = 80
group = web
group_key = 123

[test2]
type = tcp
local_port = 8081
remote_port = 80
group = web
group_key = 123
```

用户连接 frps 服务器的 80 端口,frps 会将接收到的用户连接随机分发给其中一个存活的 proxy。这样可以在一台 frpc 机器挂掉后仍然有其他节点能够提供服务。

要求 `group_key` 相同,做权限验证,且 `remote_port` 相同。

### 修改 Host Header

通常情况下 frp 不会修改转发的任何数据。但有一些后端服务会根据 http 请求 header 中的 host 字段来展现不同的网站,例如 nginx 的虚拟主机服务,启用 host-header 的修改功能可以动态修改 http 请求中的 host 字段。该功能仅限于 http 类型的代理。
Expand All @@ -525,6 +553,22 @@ host_header_rewrite = dev.yourdomain.com

原来 http 请求中的 host 字段 `test.yourdomain.com` 转发到后端服务时会被替换为 `dev.yourdomain.com`

### 设置 HTTP 请求的 header

对于 `type = http` 的代理,可以设置在转发中动态添加的 header 参数。

```ini
# frpc.ini
[web]
type = http
local_port = 80
custom_domains = test.yourdomain.com
host_header_rewrite = dev.yourdomain.com
header_X-From-Where = frp
```

对于参数配置中所有以 `header_` 开头的参数(支持同时配置多个),都会被添加到 http 请求的 header 中,根据如上的配置,会在请求的 header 中加上 `X-From-Where: frp`

### 获取用户真实 IP

目前只有 **http** 类型的代理支持这一功能,可以通过用户请求的 header 中的 `X-Forwarded-For``X-Real-IP` 来获取用户真实 IP。
Expand Down Expand Up @@ -637,7 +681,7 @@ local_port = 6000-6006,6007
remote_port = 6000-6006,6007
```

实际连接成功后会创建 6 个 proxy,命名为 `test_tcp_0, test_tcp_1 ... test_tcp_5`
实际连接成功后会创建 8 个 proxy,命名为 `test_tcp_0, test_tcp_1 ... test_tcp_7`

### 插件

Expand Down Expand Up @@ -667,7 +711,6 @@ plugin_http_passwd = abc

* frps 记录 http 请求日志。
* frps 支持直接反向代理,类似 haproxy。
* frpc 支持负载均衡到后端不同服务。
* 集成对 k8s 等平台的支持。

## 为 frp 做贡献
Expand Down
2 changes: 1 addition & 1 deletion assets/static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?b90a32ccfb87def61aaa"></script><script type="text/javascript" src="vendor.js?f04985ef00f520142368"></script></body> </html>
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>frps dashboard</title> <link rel="shortcut icon" href="favicon.ico"></head> <body> <div id=app></div> <script type="text/javascript" src="manifest.js?bc42bc4eff72df8da372"></script><script type="text/javascript" src="vendor.js?ee403fce53c8757fc931"></script></body> </html>
2 changes: 1 addition & 1 deletion assets/static/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/static/vendor.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions assets/statik/statik.go

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions client/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/fatedier/frp/g"
frpNet "github.com/fatedier/frp/utils/net"

"github.com/julienschmidt/httprouter"
"github.com/gorilla/mux"
)

var (
Expand All @@ -33,13 +33,14 @@ var (

func (svr *Service) RunAdminServer(addr string, port int) (err error) {
// url router
router := httprouter.New()
router := mux.NewRouter()

user, passwd := g.GlbClientCfg.AdminUser, g.GlbClientCfg.AdminPwd
router.Use(frpNet.NewHttpAuthMiddleware(user, passwd).Middleware)

// api, see dashboard_api.go
router.GET("/api/reload", frpNet.HttprouterBasicAuth(svr.apiReload, user, passwd))
router.GET("/api/status", frpNet.HttprouterBasicAuth(svr.apiStatus, user, passwd))
router.HandleFunc("/api/reload", svr.apiReload).Methods("GET")
router.HandleFunc("/api/status", svr.apiStatus).Methods("GET")

address := fmt.Sprintf("%s:%d", addr, port)
server := &http.Server{
Expand Down
5 changes: 2 additions & 3 deletions client/admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"sort"
"strings"

"github.com/julienschmidt/httprouter"
ini "github.com/vaughan0/go-ini"

"github.com/fatedier/frp/g"
Expand All @@ -40,7 +39,7 @@ type ReloadResp struct {
GeneralResponse
}

func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
var (
buf []byte
res ReloadResp
Expand Down Expand Up @@ -176,7 +175,7 @@ func NewProxyStatusResp(status *ProxyStatus) ProxyStatusResp {
}

// api/status
func (svr *Service) apiStatus(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
func (svr *Service) apiStatus(w http.ResponseWriter, r *http.Request) {
var (
buf []byte
res StatusResp
Expand Down
16 changes: 11 additions & 5 deletions conf/frpc_full.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ login_fail_exit = true
protocol = tcp

# specify a dns server, so frpc will use this instead of default one
dns_server = 8.8.8.8
# dns_server = 8.8.8.8

# proxy names you want to start divided by ','
# default is empty, means all proxies
Expand All @@ -56,10 +56,10 @@ dns_server = 8.8.8.8
# heartbeat_interval = 30
# heartbeat_timeout = 90

# ssh is the proxy name same as server's configuration
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as your_name.ssh
# 'ssh' is the unique proxy name
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
[ssh]
# tcp | udp | http | https, default is tcp
# tcp | udp | http | https | stcp | xtcp, default is tcp
type = tcp
local_ip = 127.0.0.1
local_port = 22
Expand All @@ -69,6 +69,10 @@ use_encryption = false
use_compression = false
# remote port listen by frps
remote_port = 6001
# frps will load balancing connections for proxies in same group
group = test_group
# group should have same group key
group_key = 123456

[ssh_random]
type = tcp
Expand Down Expand Up @@ -120,6 +124,8 @@ custom_domains = web02.yourdomain.com
# locations is only available for http type
locations = /,/pic
host_header_rewrite = example.com
# params with prefix "header_" will be used to update http request headers
header_X-From-Where = frp

[web02]
type = https
Expand All @@ -136,7 +142,7 @@ remote_port = 6003
# if plugin is defined, local_ip and local_port is useless
# plugin will handle connections got from frps
plugin = unix_domain_socket
# params set with prefix "plugin_" that plugin needed
# params with prefix "plugin_" that plugin needed
plugin_unix_path = /var/run/docker.sock

[plugin_http_proxy]
Expand Down
Loading

0 comments on commit 629f285

Please sign in to comment.