2023年11月21日新版教程

修改原因:旧的配置会导致白名单模式无法使用反向代理ssl配置,故进行更新。

主服务器转发配置

1.我这里采用 realm 进行自转发端口realm-git
安装方法就不赘述了,安装配置完毕后启动端口转发并开启开机计划任务设置
输入终端::

cat > /etc/systemd/system/emby8096.service <<EOF
[Unit]
Description=realm
After=network-online.target

[Service]
Type=simple
ExecStart=realm -l 0.0.0.0:12345 -r 0.0.0.0:8096
ExecStop=/bin/kill -INT 
Restart=always
User=root

[Install]
WantedBy=default.target
EOF

接着启动并配置开机启动任务

systemctl enable emby8096  #开机计划

systemctl start emby8096  #启动任务

由于emby的程序功能原因,这一步教程是为了你在开启白名单模式代理的同时也能用主服务器域名进行登录,如果只用代理服务器进行登录可跳过此步骤!

注意事项1


开启自转发之后,在你的主服务器域名代理ssl的端口相关配置,请填写自转发的端口
也就是刚才配置的port:12345,你自己是什么端口就填什么端口。

注意事项2

反向代理转发设置

1.首先去emby控制台的网络设置打开白名单进行设置,把你准备要代理的服务器ip填入白名单列表中。
如图:

2.其中的nginx改为

  server {
 server_name  abc你的域名.com;

client_max_body_size 6000M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
proxy_cache off;
proxy_redirect off;
proxy_buffering off;

location / {
    proxy_pass http://127.0.0.1:20111;#反代域名ip
    proxy_ssl_verify off;
    proxy_http_version 1.1;
    proxy_set_header Host 127.0.0.1:20111;#反代域名ip
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
    }
}

3.nginx任何配置修改都要记得重启和验证配置文件是否正确。
验证配置是否正确:

nginx -t

正确则会输出这样的结果:

root@ConsiderateOffbeat-VM:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

错误他会打印详细哪一行有错误,错误是什么都会告诉你,根据报错结果修改即可。

只需要复制粘贴修改其中三点#号注释,#域名就是填写访问域名,反代域名#就是填写要反代的本地端口或者你远程的域名。例:我是极光面板中转的入站本地端口8080,所以我这样写,其他自行参考。

4.修改保存重启配置依次输入终端,配置正确不会输出任何信息。这时候即可打开你的网站进行测试吧

systemctl daemon-reload
systemctl restart nginx

5.假如你用的是nginx-proxy-manager-official请参照此格式在npm设置修改:

location / {
    set              $upstream http://你的宿主机ip:12345;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_redirect http:// https://;
    proxy_buffering off;
    proxy_pass       $upstream;
    proxy_ssl_server_name on;

  }



2023年4月28日旧版教程

背景

中转ip代理设置完毕,emby网页客户端访问中转机子正常走代理流量,但是在客户端会自动回源,也就是没有经过中转机子再到客户端。遂想解决客户端回源问题。

废话不多说,开干。
我的环境:Debian11
PRETTY_NAME=”Debian GNU/Linux 11 (bullseye)”
条件1:自己已有中转端口或要反代的域名
条件2:自己先在机子安装nginx,安装方法就不赘述了,太多了~
ps:参考教程:如何在Debian 11安装Nginx

nginx基本使用小白命令必看,大佬略过Nginx命令

编辑默认nginx配置文件,任何方式打开这个文件编辑更改成如下,我这里选择nano编辑方式。

nano /etc/nginx/sites-enabled/default
  server {
 listen       80;
 server_name  xxx.com;#你的域名

client_max_body_size 6000M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For '$proxy_add_x_forwarded_for';
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
proxy_cache off;
proxy_redirect off;
proxy_buffering off;

location / {
    proxy_pass http://127.0.0.1:8080;#反代域名
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_ssl_verify off;
    proxy_http_version 1.1;
    proxy_set_header Host 127.0.0.1:8080;#反代域名
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
    }
}

修改保存重启,nginx任何配置修改都要记得重启和验证配置文件是否正确。
验证配置是否正确:

nginx -t

正确则会输出这样的结果:

root@ConsiderateOffbeat-VM:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

错误他会打印详细哪一行有错误,错误是什么都会告诉你,根据报错结果修改即可。

只需要复制粘贴修改其中三点#号注释,#域名就是填写访问域名,反代域名#就是填写要反代的本地端口或者你远程的域名。例:我是极光面板中转的入站本地端口8080,所以我这样写,其他自行参考。

接着重启nginx,每当你更改其配置时,你都需要重新加载或重新启动Nginx。重新加载将加载新配置,使用新配置启动新的woker进程并正常关闭旧woker进程。要重新加载Nginx,请使用以下命令之一

systemctl reload nginx  #任选其一
service reload nginx  #任选其一

这部分采用certbot管理部署自动ssl续期

安装:

apt install -y snapd
sudo snap install core; sudo snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
certbot --agree-tos --nginx --email #填你邮箱 -d #填你域名
# 例:certbot --agree-tos --nginx --email [email protected] -d www.baidu.com

设置定时任务

crontab -e

填入如下

0 0 1 * * /usr/bin/certbot renew --force-renewal

我这里保存编辑方式跟vi的方式一样,键入i编辑,esc返回键入:wq 进行保存即可。根据自己环境编辑保存,有的是nano。
查看文件crontab

nano /etc/crontab

是否跟我的一致,不一致则根据情况修改。

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

教程完毕,其他系统环境配置参考官方说明,都有非常详细的步骤。
certbot官网