Loading... # Synology run frp in PM2 at boot and reverse proxy ssh/http service ## Server Side ### installation ```bash > wget https://github.com/fatedier/frp/releases/download/v0.36.2/frp_0.36.2_linux_amd64.tar.gz > tar zxvf frp_0.36.2_linux_amd64.tar.gz > pm2 start frps -- -c frps.ini > pm2 save ``` ### frps config file ```ini [common] bind_port = [server port] bind_udp_port = [server udp port] vhost_http_port = 8088 authentication_method = token token = [client auth token] dashboard_addr = 127.0.0.1 dashboard_port = [dashbaord port] dashboard_user = ****** dashboard_pwd = ****** ``` ### nginx config file ```nginx upstream frps { server 127.0.0.1:8088; } server { listen 80; server_name [your hostname]; client_max_body_size 100M; location / { proxy_pass http://frps; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; } } ``` If you want to add https, just do it in nginx file. ## Client side ### installation ```bash > wget https://github.com/fatedier/frp/releases/download/v0.36.2/frp_0.36.2_linux_amd64.tar.gz > tar zxvf frp_0.36.2_linux_amd64.tar.gz > pm2 start frpc > pm2 save ``` ### frpc config file ```ini [common] server_addr = [frps server address] server_port = [server port] authentication_method = token token = [client auth token] [ssh] type = tcp local_ip = 127.0.0.1 local_port = [local ssh port] remote_port = [remote port to listen] [web] type = http local_port = [local web server port] custom_domains = [optional custom domain] ``` ### synology startup script also check https://help.synology.com/developer-guide/integrate_dsm/run_with_system_boot.html ```bash > cd /usr/local/etc/rc.d/ > sudo vim pm2.sh > sudo chmod 755 pm2.sh ``` pm2.sh content, thanks to https://gist.github.com/GManzato/43e6c8c67a3e87b2f1830d957036f5f6 slightly edited ```bash #!/bin/sh : ${pm2_user="admin"} command="/usr/local/lib/node_modules/pm2/bin/pm2" pidfile="/volume4/homes/NULL/.pm2/NULL.pid" super() { su - "NULL" -c "$*" } pm2_start() { unset "NULL_cmd" if pm2_running; then echo "Pm2 is already running, 'pm2 list' to see running processes" else echo "Starting pm2." super $command resurrect fi } pm2_stop() { echo "Stopping NULL..." #super $command dump super $command delete all super $command kill } pm2_reload() { echo "Reloading NULL" super $command reload all } pm2_status() { super $command list } pm2_running() { process_id=$(pgrep -F NULL) if [ "NULL" -gt 0 ]; then return 0 else return 1 fi } case "$1" in start) pm2_start ;; stop) pm2_stop ;; restart) pm2_reload ;; status) pm2_status ;; *) esac ``` reboot to see if it works Last modification:May 26th, 2021 at 02:41 pm © 允许规范转载