安装ngrok
安装完毕后ngrok默认将服务器的80端口占用。这时,需要修改启动脚本。
vim /etc/init.d/ngrokd
找到如下部分
nohup sudo ./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="muumlover.com" -httpAddr=":80" -httpsAddr=":443" &
将-httpAddr=":80" -httpsAddr=":443"
修改为-httpAddr=":8080" -httpsAddr=":8043"
以释放80端口。
安装nginx
apt-get install nginx -y
修改nginx配置
cd /etc/nginx/conf.d/
touch server.conf
vim server.conf
如下将*.example.com:80
的请求全部转发到*.example.com:8080
server {
listen 80;
server_name *.example.com;
keepalive_timeout 70;
proxy_set_header "Host" $host:8080;
location / {
proxy_pass_header Server;
proxy_redirect off;
proxy_pass http://127.0.0.1:8080;
}
access_log off;
log_not_found off;
}
开启/usr/local/src/ngrok/bin
的文件访问权限。
server {
listen 80;
server_name ngrok.example.com;
root /usr/local/src/ngrok/bin;
location / {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
}
重新载入nginx
使改动生效
nginx -s reload