nginx + frp 实现内网穿透 Published on Dec 3, 2020 in linuxmac with 0 comment [nginx下载](http://nginx.org/en/download.html) [frp下载](https://github.com/fatedier/frp) nginx设置: ```nginx server { listen 80; server_name helloword.cn; location / { # 这里的端口需要跟frps的vhost_http_port的设置保持一致 proxy_pass http://127.0.0.1:8080/; proxy_set_header Host $host; proxy_set_header Remote_Addr $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; } } ``` 检测一下配置文件 ```bash nginx -t ``` 重启nginx ```bash nginx -s reload # 这个是热启动 ``` 配置frp服务端 ``` [common] bind_port = 9999 vhost_http_port = 8080 max_pool_count = 1 ``` 配置frp客户端 ``` [common] server_addr = 120..... ;服务器地址 server_port = 9999 log_max_days = 3 [web] type = http local_port = 8080 local_ip = 127.0.0.1 custom_domains = comp.helloword.cn ``` 后台启动frp服务 ```bash nohup /usr/local/frp/frps -c /usr/local/frp/frps.ini & ``` ## https支持 配置好https后,假设你有一个http服务的域名是 `yourdomain.com` ```nginx location / { proxy_pass http://yourdomain.com; # 这里也可以指向80端口,不过一般80端口是被占用的 } ``` 然后就可以通过http的内网穿透通过https来访问 ## yum安装frps ```bash cd /tmp # 可能需要访问境外网 wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh chmod 777 install-frps.sh ./install-frps.sh install ``` frps命令 ```bash # 启动服务: frps start # 停止服务: frps stop # 重启服务 frps restart # 运行状态 frps status # 参数 frps config # 版本 frps version ``` > 默认配置文件在 `/usr/local/frps/frps.ini` ## 通过systemctl来启动frps 创建文件服务文件 ```bash vim /lib/systemd/system/frps.service ``` 输入配置内容 ```bash [Unit] Description=frps service After=syslog.target network.target Wants=network.target [Service] Type=simple ExecStart=frps -c /usr/local/frps/frps.ini [Install] WantedBy=multi-user.target ``` 然后用systemctl命令来启动 ```bash systemctl start frps ``` 开机自动启动 ```bash systemctl enable frps ``` 本文由 tutustack 创作,采用 知识共享署名4.0 国际许可协议进行许可本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名