Mac 设置
I. enable IP Forwarding
1. 开机启用
新建或编辑 /etc/sysctl.conf 文件
加入内容:
net.inet.ip.forwarding=1
加入内容:
net.inet.ip.forwarding=1
2. 现在启用
$ sudo sysctl -w net.inet.ip.forwarding=1
$ sudo sysctl -w net.inet.ip.forwarding=1
II. set Traffic Redirection (Port Forwarding)
编辑 pf 配置文件
编辑 /etc/pf.conf 文件[^1]
在 rdr-anchor 下面新增一行
rdr-anchor "ps4"
在 load anchor 下面新增一行
load anchor "ps4" from "/etc/pf.anchors/ps4"
新建 /etc/pf.anchors/ps4 文件[^1]
内容:
rdr pass on en0 inet proto tcp from any to 199.9.0.0/16 port 1935 -> 127.0.0.1 port 1935
[^1] 文件需要以空行结尾
在 rdr-anchor 下面新增一行
rdr-anchor "ps4"
load anchor "ps4" from "/etc/pf.anchors/ps4"
内容:
rdr pass on en0 inet proto tcp from any to 199.9.0.0/16 port 1935 -> 127.0.0.1 port 1935
启用 pf 规则
1. 现在启用
# 重新加载 pf 规则
$ sudo pfctl -f /etc/pf.conf
# 启用 pf
$ sudo pfctl -e
# 重新加载 pf 规则
$ sudo pfctl -f /etc/pf.conf
# 启用 pf
$ sudo pfctl -e
2. 开机启用
编辑 /System/Library/LaunchDaemons/com.apple.pfctl.plist 文件
在 pfctl 下面加入一行
<string>-e</string>
在 pfctl 下面加入一行
<string>-e</string>
III. set nginx rtmp server
安装 nginx
# http://brew.sh/homebrew-nginx/
$ brew tap homebrew/nginx
$ brew install nginx-full --with-rtmp-module
# http://brew.sh/homebrew-nginx/
$ brew tap homebrew/nginx
$ brew install nginx-full --with-rtmp-module
配置 nginx
编辑 /usr/local/etc/nginx/nginx.conf 文件
与 http 同级,加入
rtmp {
server {
listen 1935;
chunk_size 131072;
max_message 256M;
application app {
live on;
record off;
meta copy;
push rtmp://直播地址;
}
}
}
与 http 同级,加入
rtmp {
server {
listen 1935;
chunk_size 131072;
max_message 256M;
application app {
live on;
record off;
meta copy;
push rtmp://直播地址;
}
}
}
开启 nginx
# Start process:
$ sudo nginx
# Reload config:
$ sudo nginx -s reload
# Stop process:
$ sudo nginx -s stop
# Start process:
$ sudo nginx
# Reload config:
$ sudo nginx -s reload
# Stop process:
$ sudo nginx -s stop