frp 和 nginx 搭建一个内网穿透服务器

相关资料

下载

下载地址:https://github.com/fatedier/f...
选择对应的版本进行下载php

wget https://github.com/fatedier/frp/releases/download/v0.21.0/frp_0.21.0_linux_386.tar.gz

若是是windows须要下载windos版本html

wget https://github.com/fatedier/frp/releases/download/v0.21.0/frp_0.21.0_darwin_amd64.tar.gz

下载后、个人服务端是centos 客户端是windowslinux

服务端须要关注的文件是 frps、frps.ini
客户端须要关注的文件是 frpc(或者是frpc.exe)、frpc.ini

注意,若是运行的环境是windows就要运行windows版本的,也就是exe后缀的nginx

配置服务端

配置文件

# frps.ini
[common]
#服务端须要开启的端口(与客户端绑定的进行通讯的端口)
bind_port = 7000
#服务端须要开启的端口(访问客户端web服务自定义的端口号)
vhost_http_port = 8081
auth_token = websong

type = http
custom_domains = abc.baidu.com
auth_token = websong

配置文件说明

  • bind_port
    服务端须要开启的端口
  • vhost_http_port
    服务端须要开启的端口
  • auth_token
    须要客户端的auth_token与此同样
  • type
    其实除了http还有其余参数,好比tcp,这里只讲述http,其余的请看相关文档: https://github.com/fatedier/frp
  • custom_domains
    域名
    具体接下来在配置客户端说明

启动服务

正常启动,ctrl+c能推出git

./frps -c ./frps.ini

后台启动github

nohup ./frps -c ./frps.ini &

若是有兴趣,更能够设置成开机启动(这里不讲述)web

配置客户端

配置文件

# frpc.ini
[common]
server_addr = 48.104.176.184
server_port = 7000
auth_token = websong

[web6]
type = http
local_port = 80
custom_domains =b.abc.baidu.com

配置文件讲解

  • server_addr
    对应服务器ip ,
  • server_port
    与服务端配置bind_port同样
  • auth_token
    与服务端配置auth_token同样
  • [web6]
    这个是惟一的,假如在另一个客户端用了web6将会报明显的错误
  • local_port
    此端口,假如是80,那就是访问客户端机器的80端口
  • custom_domains
    域名 这里重点说一下,这个参数能够填的域名有shell

    abc.baidu.com
    *.abc.baidu.com

    可是,这些域名都是须要解析到服务器ip的
    *.abc.baidu.com 这里就须要使用到域名泛解析
    具体百度便可windows

客户端启动

./frpc -c ./frpc.ini

windowscentos

./frpc.exe -c ./frpc.ini

后台启动前面加 nohup 跟服务端同样

nohup ./frpc.exe -c ./frpc.ini

穿透成功

启动网站

若是以上服务端启动,客户端启动都没问题的话
以客户端的配置的域名:custom_domains
和 服务端配置的端口vhost_http_port在浏览器打开便可
也就是 b.abc.baidu.com:8081
其实这些就至关于访问你客户端本机的
127.0.0.1:80 或者localhost:80,
这个80端口是客户端配置文件的的local_port

至此内网穿透完成

可是

  • 可是刚刚有没有发现,访问的是带端口的网址,b.abc.baidu.com:8081
  • 若是不想带端口呢,浏览器的默认端口是80,也就是说,我把服务端vhost_http_port,配置成80就行了,固然这样能解决
  • 可是若是服务器有其余程序占用80端口呢,好比nginx,总不能把nginx换成其余端口吧,那个人博客www.blog.com就由于这个得改为www.blog.com:9090 假设改为9090,因此确定有办法公用的
  • 办法就是,咱们能够利用nginx的反向代理就能完成,请接下来往下看 配置nginx

原文地址:http://www.taoluyuan.com/index.php/archives/42/

配置nginx

配置文件

server{
 listen 80;
    server_name *.abc.baidu.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/abc/;

 location / 
    {
        proxy_pass http://48.104.176.184:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;                       
    }
}

说明

如配置文件所属

  • 原本是须要访问 http://b.abc.baidu.com:8081 的
  • nginx使用了泛域名配置,*.abc.baidu.com (你本身的域名确定不同)
server_name *.abc.baidu.com;
  • 反向代理配置
proxy_pass http://48.104.176.184:8081;

ip是服务端的ip,端口是服务端配置vhost_http_port 8081

至于nginx的其余参数,跟日常大多数nginx配置网站参数同样
这里使用到了nginx泛域名解析,和反向代理

完成打开网站

若是客户端配置的custom_domains是b.abc.baidu.com
在浏览器输入 b.abc.baidu.com ,就不用带端口号8081 ,应为已经被nginx反向代理了;
这样作的好处是

  • 使用的时候直接在浏览器输入域名就能够,不用输入端口,用户也不用知道服务端的vhost_http_port 端口是什么,
  • 让服务器其余网站的端口能够不用改;

原文地址:http://www.taoluyuan.com/index.php/archives/42/

相关文章
相关标签/搜索