<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>quakemachineX</title>
	<link>https://www.quakemachinex.com/blog</link>
	<description>EX</description>
	<pubDate>Wed, 16 Jul 2025 06:44:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>网易 UU 加速器与 Proxifier 的冲突以及解决</title>
		<link>https://www.quakemachinex.com/blog/307.html</link>
		<comments>https://www.quakemachinex.com/blog/307.html#comments</comments>
		<pubDate>Thu, 05 Dec 2024 16:42:01 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/307.html</guid>
		<description><![CDATA[三角洲行动国际服上线，想来玩一把，没想到遇到一堆问题。由于国际服是强制锁区，所以 UU 加速开启国际服加速时，会一并加速 Steam 客户端，否则游戏会提示 “对此地区不可用”。由于不想]]></description>
			<content:encoded><![CDATA[<p>三角洲行动国际服上线，想来玩一把，没想到遇到一堆问题。由于国际服是强制锁区，所以 UU 加速开启国际服加速时，会一并加速 Steam 客户端，否则游戏会提示 “对此地区不可用”。由于不想多个虚拟网卡，所以之前我一直只用 进程加速 模式。启动 UU 加速器后再启动 Steam 客户端，发现商店就进不去，Proxifier 日志疯狂报错：</p>
<p><a  rel="prettyPhoto" title="proxifier_uu" title="" href="https://www.quakemachinex.com/blog/wp-content/images/proxifier_uu_log.jpg"><img class="c" src="https://www.quakemachinex.com/blog/wp-content/images/_proxifier_uu_log.jpg" title="" alt="" width="580" height="172" /></a></p>
<p>这个  127.100.163.1 从哪来的呢？ 通过分析 UU 日志，发现 UU 修改了系统 hosts 文件，添加了如下内容：</p>
<p><img class="c" src="https://www.quakemachinex.com/blog/wp-content/images/proxifier_hosts.jpg" title="" alt="" width="448" height="558" /></p>
<p>然后通过邮件联系 Proxifier 支持，官方回复解决方法如下：</p>
<blockquote><p>Add the following key to HKEY_CURRENT_USER\Software\Initex\Proxifier\Settings:<br />
FakeSubnet(REG_DWORD)=100 (64 in hex)</p>
<p>Alternatively, you can use this command to create the key automatically:<br />
reg add HKCU\Software\Initex\Proxifier\Settings /v FakeSubnet /t REG_DWORD /d 100</p>
<p>To activate the option, you need to restart Proxifier. It should output message like the following on start:<br />
Fake IPv4 subnet = 100</p></blockquote>
<p>1. 注册表编辑器找到 HKEY_CURRENT_USER\Software\Initex\Proxifier\Settings ，添加 REG_DWORD, 名称 FakeSubnet ， 值为 100 （16进制的 64）；<br />
2. 或者直接用以下命令：</p>
<blockquote class="purecode"><p>
reg add HKCU\Software\Initex\Proxifier\Settings /v FakeSubnet /t REG_DWORD /d 100
</p></blockquote>
<p>然后重启 Proxifier 即可。修改成功的话启动日志会有：</p>
<blockquote class="purecode"><p>
Fake IPv4 subnet = 100
</p></blockquote>
<p>BTW: 后续发现，只有在使用 UU 加速器 进程模式 且选择特定的一些服务器上会出现这个冲突，路由模式是没有问题的，因为路由模式并不会修改 hosts 文件。进程模式有一些服务器也不会有问题，这时候打开 hosts 文件你会发现 UU 添加的项目 IP 不是 fake IP 而是真实的 IP 地址。冲突的根源就是当 UU 添加了类似 127.100.*.* 的项目到 hosts 文件中时，会与 Proxifier 的远程 <a style="border-bottom: 1px dashed #000000; cursor: help;" title="Domain Name System或者Domain Name Service（域名系统或者余名服务）。域名系统为Internet上的主机分配域名地址和IP地址。用户使用域名地址，该系统就会自动把域名地址转为IP地址。域名服务是运行域名系统的Internet工具。执行域名服务的服务器称之为DNS服务器，通过DNS服务器来应答域名服务的查询。" href="http://www.webopedia.com/TERM/D/DNS.html" rel="external">DNS</a> 解析使用的 fake IP 池冲突（127.8.*.*）</p>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/307.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>全图形界面备份 Phicomm N1 在 U 盘上的系统</title>
		<link>https://www.quakemachinex.com/blog/306.html</link>
		<comments>https://www.quakemachinex.com/blog/306.html#comments</comments>
		<pubDate>Sun, 07 Jul 2024 09:10:10 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[System]]></category>

		<category><![CDATA[Hardware]]></category>

		<category><![CDATA[Router]]></category>

		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/306.html</guid>
		<description><![CDATA[运行在 U 盘的系统随着时间推移越来越大已经不能备份在 N1 的 EMMC 里，突然损坏的话就要做很多重复工作来复原。直接做盘对盘克隆有个限制就是目标盘必须比源盘容量大，同样是标称 8G 的 U ]]></description>
			<content:encoded><![CDATA[<p>运行在 U 盘的系统随着时间推移越来越大已经不能备份在 N1 的 EMMC 里，突然损坏的话就要做很多重复工作来复原。直接做盘对盘克隆有个限制就是目标盘必须比源盘容量大，同样是标称 8G 的 U 盘，非常有可能实际可用容量是不一样的，之前就是因为这样把一个 8G 的系统盘一直备份成了 64G 的 U 盘.。。。将要介绍的备份方法则没有这个限制，只要主分区（一般是 ROOTFS）的实际数据使用量不大于备份盘容量即可。</p>
<p>首先用 DiskGenius 将 U 盘的两个主要分区备份为: BOOT.pmf 和 ROOTFS.pmf 文件。注意这里 BOOT 分区备份最好选择 “备份所有扇区” 模式，因为这个分区并不大；而 ROOTFS 分区则选择 “按文件备份” 模式，这样我们就可以把整个系统恢复到较小的 U 盘上。（只要实际数据不大于恢复盘的总容量）</p>
<p>然后在 Linux 桌面模式（可以是虚拟机）把原系统的<span style="color:red">初始镜像</span> (比如： Armbian_20.10_Arm-64_focal_current_5.9.0.img) 恢复到新的 U 盘。因为初始镜像最小，我们其实只需要恢复这个系统默认的分区表和文件结构。这里推荐使用 balenaEtcher。恢复完成后用 GParted 或者 KDE Partition Manager 无损调整 ROOTFS 分区至你需要的大小，还可以在这个阶段创建 SWAP 分区。这一步理论上也可以在 Windows 下完成，比如恢复用 USB Image Tool，balenaEtcher Windows 版本等工具，然后用 DiskGenius 调整分区大小，但经过数次测试，这些对于 EXT 分区的操作在 Windows 下非常容易出错不能完成，或者完成后的 U 盘不能启动，或者是文件结构/分区表有问题。</p>
<p>最后在 DiskGenius 中把之前备份的 BOOT 和 ROOTFS 文件恢复到 U 盘对应的分区。</p>
<p>保险起见可以把这个盘最后一次加载到 Liunx 下用 fsck 检查一下各个分区。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/306.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>静态编译 Zerotier 的一些问题及解决</title>
		<link>https://www.quakemachinex.com/blog/305.html</link>
		<comments>https://www.quakemachinex.com/blog/305.html#comments</comments>
		<pubDate>Sat, 29 Jun 2024 11:00:38 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/305.html</guid>
		<description><![CDATA[armv5 架构下用 Tomatoware 静态编译 Zerotier 会出现 atomic 原子操作错误，解决的办法就是增加 -latomic 和删除 -pie:

#atomic error, add -latomic and delete -pie

# Static builds, which are currently done for a number of Linux ta]]></description>
			<content:encoded><![CDATA[<p>armv5 架构下用 Tomatoware 静态编译 Zerotier 会出现 atomic 原子操作错误，解决的办法就是增加 <span style="color:green">-latomic</span> 和删除 <span style="color:red">-pie</span>:</p>
<pre class="prettyprint">
#atomic error, add -latomic and delete -pie

# Static builds, which are currently done for a number of Linux targets
ifeq ($(ZT_STATIC),1)
	override LDFLAGS+=-static
	LDLIBS+=-latomic
endif

LDFLAGS=-pie -Wl,-z,relro,-z,now  ----> LDFLAGS=-Wl,-z,relro,-z,now
</pre>
<p>VFP 相关错误则需要修改 make-linux.mk 文件:</p>
<pre class="prettyprint">
# ARM32 hell -- use conservative CFLAGS
ifeq ($(ZT_ARCHITECTURE),3)
	ifeq ($(shell if [ -e /usr/bin/dpkg ]; then dpkg --print-architecture; fi),armel)
		override CFLAGS+=-march=armv5t -mfloat-abi=soft -msoft-float -mno-unaligned-access -marm
		override CXXFLAGS+=-march=armv5t -mfloat-abi=soft -msoft-float -mno-unaligned-access -marm
		ZT_USE_ARM32_NEON_ASM_CRY<a style="border-bottom: 1px dashed #000000; cursor: help;" title="Private Tracker， 是 BitTorrent Tracker 的一种，相对于Public Tracker，它限制使用，需要用户在网站注册。在绝大多数 Private Tracker 中管理注册的方式为通过邀请机制，即活跃和有贡献的用户具有邀请新成员加入的能力。邀请一般通过电子邮件或邀请码发送，一般只有满足一定上传量或达到一定上传/下载比率（分享率）的用户才能获得。买卖邀请名额的行为在 Private Tracker 社区一般被严格禁止，因为这使得反盗版的机构更容易地侵入 Private Tracker 。大部分 Private Tracker 记录用户的上传量和下载量，并且在大多数情况下会要求一个最低的分享率。" href="http://acronyms.thefreedictionary.com/PT" rel="external">PT</a>O=0
	else
		override CFLAGS+=-march=armv5t -mfloat-abi=soft -msoft-float -mno-unaligned-access -marm
		override CXXFLAGS+=-march=armv5t -mfloat-abi=soft -msoft-float -mno-unaligned-access -marm
		ZT_USE_ARM32_NEON_ASM_CRYPTO=0
	endif
endif
</pre>
<p>Phicomm N1 下 aarch64 编译应使用：</p>
<pre class="prettyprint">
CC=aarch64-linux-gcc CXX=aarch64-linux-g++ make -j`nproc` ZT_STATIC=1 ZT_SSO_SUPPORTED=0 ZT_CONTROLLER=0
</pre>
<p>因为如果编译 ZT_CONTROLLER 就需要 Rust，耗时太长，没什么必要。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/305.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>解除 YouTube "广告拦截器违反《YouTube 服务条款》" 提示的方法</title>
		<link>https://www.quakemachinex.com/blog/304.html</link>
		<comments>https://www.quakemachinex.com/blog/304.html#comments</comments>
		<pubDate>Sun, 29 Oct 2023 08:14:35 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/304.html</guid>
		<description><![CDATA[1. 下载并安装 uBlock Origin。
2. 打开插件, 点击右侧齿轮图标, 选择"自定义静态规则", 贴入以下代码:

youtube.com##+js(set, yt.config_.openPopupConfig.supportedPopups.adBlockMessageViewModel, false)
youtube.com##+js(set, Objec]]></description>
			<content:encoded><![CDATA[<p>1. 下载并安装 <a href="https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm" title="" rel="external">uBlock Origin</a>。</p>
<p>2. 打开插件, 点击右侧齿轮图标, 选择"自定义静态规则", 贴入以下代码:</p>
<blockquote class="purecode"><p>
youtube.com##+js(set, yt.config_.openPopupConfig.supportedPopups.adBlockMessageViewModel, false)<br />
youtube.com##+js(set, Object.prototype.adBlocksFound, 0)<br />
youtube.com##+js(set, ytplayer.config.args.raw_player_response.adPlacements, [])<br />
youtube.com##+js(set, Object.prototype.hasAllowedInstreamAd, true)
</p></blockquote>
<p>3. 在 uBlock Origin 设定页面中，选择“规则列表”，按下“清除所有缓存”，接着按“立即更新”。</p>
<p>4. 在 Youtube 页面，关闭除了 uBlock Origin 以外的其它广告拦截器，如 Adblock。</p>
<p>5. 刷新页面即可。</p>
<p>6. 若突然无法观看，请重复步骤 3。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/304.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>撸一个批处理优化视频网页传输</title>
		<link>https://www.quakemachinex.com/blog/302.html</link>
		<comments>https://www.quakemachinex.com/blog/302.html#comments</comments>
		<pubDate>Thu, 07 Oct 2021 07:13:06 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/302.html</guid>
		<description><![CDATA[哦，原来视频流式传输需要这么优化： 
Optimizing MP4 Video for Fast Streaming
Tools to fix MP4 videos so players can start playback instantly (without downloading the whole file)
Understanding the M.P.E.G-4 moov atom: Pseudo-Streaming in Mp]]></description>
			<content:encoded><![CDATA[<p>哦，原来视频流式传输需要这么优化： </p>
<blockquote><p><a href="https://rigor.com/blog/optimizing-mp4-video-for-fast-streaming/" title="Optimizing MP4 Video for Fast Streaming" rel="external">Optimizing MP4 Video for Fast Streaming</a><br />
<a href="http://muzso.hu/2012/11/14/tools-to-fix-mp4-videos-so-players-can-start-playback-instantly-without-downloading-the-w" title="" rel="external">Tools to fix MP4 videos so players can start playback instantly (without downloading the whole file)</a><br />
<a href="https://sanjeev-pandey.medium.com/understanding-the-mpeg-4-moov-atom-pseudo-streaming-in-mp4-93935e1b9e9a" title="" rel="external">Understanding the M.P.E.G-4 moov atom: Pseudo-Streaming in Mp4</a></p></blockquote>
<p>检测视频文件是否已经为流式传输优化：</p>
<pre class="prettyprint" lang-bash>
mp4box -info A.mp4 2>&#038;1 1>NUL | find "File suitable for progressive download (moov before mdat)"
#或者
AtomicParsley input.mp4 -T | sed -n 2p | grep -q "moov" &#038;& echo "yup" || echo "nope"
</pre>
<p>那么就撸个批处理干，支持 mp4/mkv/mov/m4v 格式的优化。</p>
<pre class="prettyprint lang-bash">
#!/bin/bash

[ -n "$1" ] &#038;& {
    src_folder="$1"
} || {
    echo "input you source folder location."
    exit
}

src_empty=$(ls -A "$src_folder")

[ -n "$src_empty" ] &#038;& {
    for file_a in ${src_folder}/*
    do
        in_full_filename=$(basename "$file_a")
        in_filename="${filename%.*}"
        in_extension="${file_a##*.}"
        out_full_filename="${in_filename}_.${in_extension}"

        echo "src=$in_full_filename ndst=$out_full_filename"

        case $in_extension in
            mp4|mov|m4v)
                ffmpeg -i "${src_folder}/${in_full_filename}" -movflags faststart -acodec copy -vcodec copy -copyts "${src_folder}/$out_full_filename"
                ;;
            mkv)
                ffmpeg -i "${src_folder}/${in_full_filename}" -c copy -reserve_index_space 100k -copyts "${src_folder}/$out_full_filename"
                ;;
            *)
                echo "${in_extension} file not support faster start."
                ;;
        esac

        [ $? -eq 0 ] &#038;& {
            rm -f "${src_folder}/${in_full_filename}"
            mv -f "${src_folder}/$out_full_filename" "${src_folder}/${in_full_filename}"
            echo "-----------${in_filename} now faster web loading------------"
        } || {
            echo "-----------${in_filename} faster process failed------------"
        }
    done
} || {
    echo "Source folder is empty."
}
</pre>
<p>Windows 版本，丢到要处理的视频目录下：</p>
<pre class="prettyprint" lang-bat>
for /r %%F in (*.mp4) do (
    ffmpeg.exe  -i "%%F" -movflags faststart -acodec copy -vcodec copy -copyts "%%~dpnF"_.mp4
    if not errorlevel 1 if exist "%%~dpnF.mp4" (
		del /q "%%F"
		move "%%~dpnF"_.mp4 "%%F"
	)
)

for /r %%F in (*.mov) do (
    ffmpeg.exe  -i "%%F" -movflags faststart -acodec copy -vcodec copy -copyts "%%~dpnF"_.mov
    if not errorlevel 1 if exist "%%~dpnF.mov" (
		del /q "%%F"
		move "%%~dpnF"_.mov "%%F"
	)
)

for /r %%F in (*.mkv) do (
    ffmpeg.exe  -i "%%F" -c copy -reserve_index_space 100k -copyts "%%~dpnF"_.mkv
    if not errorlevel 1 if exist "%%~dpnF.mkv" (
		del /q "%%F"
		move "%%~dpnF"_.mkv "%%F"
	)
)

for /r %%F in (*.wmv) do (
    ffmpeg.exe  -i "%%F" -movflags faststart -copyts "%%~dpnF".mp4
    if not errorlevel 1 if exist "%%~dpnF.wmv" (
		del /q "%%F"
	)
)

for /r %%F in (*.mpg) do (
    ffmpeg.exe  -i "%%F" -movflags faststart -copyts "%%~dpnF".mp4
    if not errorlevel 1 if exist "%%~dpnF.mpg" (
		del /q "%%F"
	)
)

for /r %%F in (*.flv) do (
    ffmpeg.exe  -i "%%F" -movflags faststart -copyts "%%~dpnF".mp4
    if not errorlevel 1 if exist "%%~dpnF.flv" (
		del /q "%%F"
	)
)

for /r %%F in (*.rmvb) do (
    ffmpeg.exe  -i "%%F" -movflags faststart -copyts "%%~dpnF".mp4
    if not errorlevel 1 if exist "%%~dpnF.rmvb" (
		del /q "%%F"
	)
)

for /r %%F in (*.rm) do (
    ffmpeg.exe  -i "%%F" -movflags faststart -copyts "%%~dpnF".mp4
    if not errorlevel 1 if exist "%%~dpnF.rm" (
		del /q "%%F"
	)
)
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/302.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>已保护：Nginx 反代小草的方法 - 境外&#038;境内</title>
		<link>https://www.quakemachinex.com/blog/301.html</link>
		<comments>https://www.quakemachinex.com/blog/301.html#comments</comments>
		<pubDate>Wed, 06 Oct 2021 13:28:13 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[Entertainment]]></category>

		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/301.html</guid>
		<description><![CDATA[被密码保护的文章没有摘录。]]></description>
			<content:encoded><![CDATA[<form action="https://www.quakemachinex.com/blog/wp-pass.php" method="post">
<p>这篇文章已被密码保护。请在这里输入密码：</p>
<p><label>密码：<br />
<input name="post_password" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="提交" /></p></form>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/301.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>VPS 搭建自己的 Youtube 网页下载服务 - MeTube</title>
		<link>https://www.quakemachinex.com/blog/300.html</link>
		<comments>https://www.quakemachinex.com/blog/300.html#comments</comments>
		<pubDate>Tue, 05 Oct 2021 18:19:32 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[Entertainment]]></category>

		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/300.html</guid>
		<description><![CDATA[详情见 MeTube 主页，我这里流水账一下：

#安装、升级 npm / n
apt install npm
npm -g install n
n lts

cd metube/ui

# 安装 Angular，构建 UI
npm install
node_modules/.bin/ng build

# 安装 Python 依赖
cd ..
pip3 install pipenv
pip]]></description>
			<content:encoded><![CDATA[<p>详情见 <a href="https://github.com/alexta69/metube" title="" rel="external">MeTube 主页</a>，我这里流水账一下：</p>
<pre class="prettyprint">
#安装、升级 npm / n
apt install npm
npm -g install n
n lts

cd metube/ui

# 安装 Angular，构建 UI
npm install
node_modules/.bin/ng build

# 安装 Python 依赖
cd ..
pip3 install pipenv
pipenv install
python3 -m pip install aiohttp
pipenv install aiohttp

#安装 ffmpeg，合并音频视频，Youtube 新视频基本都需要合并
apt install ffmpeg

# 自定义环境文件测试运行
export DOWNLOAD_DIR=/home/wwwroot/metube
export URL_PREFIX=/metube
pipenv run python3 app/main.py
</pre>
<p>正常会输出：</p>
<blockquote><p>INFO:ytdl:waiting for item to download<br />
======== Running on http://0.0.0.0:8081 ========<br />
(Press CTRL+C to quit)</p></blockquote>
<p>可以浏览器连接： http://VPS-IP:8081，测试一下下载，没问题往下走。</p>
<p>配置 Nginx 转发：</p>
<pre class="prettyprint">
#主转发代码
        location /metube/ {
            proxy_pass http://127.0.0.1:8081;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
        }
#没有问题这一块可以不要
        location ~* .(css|js)$ {
            proxy_pass http://127.0.0.1:8081;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
        }
</pre>
<p>添加到开机自动运行：</p>
<blockquote class="purecode"><p>
systemctl edit metube --full --force
</p></blockquote>
<p>粘贴如下代码，metube 源码路径，下载路径，反代目录，改成自己的：</p>
<pre class="prettyprint">
[Unit]
Description=Metube Web Service
After=network.target

[Service]
Environment=DOWNLOAD_DIR=/home/wwwroot/metube
Environment=URL_PREFIX=/metube
Restart=always
Type=simple
WorkingDirectory=/root/src/metube
ExecStart=/usr/local/bin/pipenv run python3 /root/src/metube/app/main.py

[Install]
WantedBy=multi-user.target
</pre>
<p>然后执行：</p>
<blockquote class="purecode"><p>
systemctl enable --now metube
</p></blockquote>
<p>metube 就启动了，并且下次开机也会自己启动。</p>
<p>追加：<br />
添加简单的密码认证：</p>
<pre class="prettyprint">
#生成密码文件，添加用户名
sudo sh -c "echo -n 'sammy:' >> /etc/nginx/.htpasswd"
#为此用户设置密码
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
</pre>
<p>然后添加到 metube 反代中：</p>
<pre class="prettyprint">
location /metube/ {
    auth_basic           "Administrator’s Area";
    auth_basic_user_file /etc/nginx/.htpasswd";
    ...
}
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/300.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Nginx SNI 分流反代后 CSS JS 文件 404 找不到的问题（不完美解决）</title>
		<link>https://www.quakemachinex.com/blog/299.html</link>
		<comments>https://www.quakemachinex.com/blog/299.html#comments</comments>
		<pubDate>Tue, 05 Oct 2021 17:57:49 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[System]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/299.html</guid>
		<description><![CDATA[这里试过反代 ifile share，cloudreve，metube 等都出现这个问题，主页面可以显示，表示反代是没有问题的，但是所有 css，js 文件都是 404，界面显示不完全，很奇怪，你说都是静态文件，但 favicon.ico]]></description>
			<content:encoded><![CDATA[<p>这里试过反代 ifile share，cloudreve，metube 等都出现这个问题，主页面可以显示，表示反代是没有问题的，但是所有 css，js 文件都是 404，界面显示不完全，很奇怪，你说都是静态文件，但 favicon.ico 那些没问题。</p>
<p>原本反代代码，css/js 404 出错：</p>
<pre class="prettyprint">
        location / {
            proxy_set_header Host $host;
            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_redirect off;
            proxy_pass http://127.0.0.1:808;
            add_header X-Cache $upstream_cache_status;
            add_header Cache-Control no-cache;
        }
</pre>
<p>添加以下代码，则正常：</p>
<pre class="prettyprint">
        location ~* \.(gif|png|jpg|css|js|woff|woff2)$ {
            proxy_set_header Host $host;
            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_redirect off;
            proxy_pass http://127.0.0.1:808;
            expires 12h;
        }
</pre>
<p>这里有个问题，如果反代不是在 / 下，而是子目录下，比如 /metube，按照上面的写法就会影响到 / 下主站，导致主站找不到一些资源文件，<del datetime="2021-10-10T18:21:23+00:00">我这里就出现修改后主站找不到 favicon.png 的问题，所以我就只添加 css|js</del> 添加子目录匹配：</p>
<pre class="prettyprint">
        location /metube/ {
            proxy_pass http://127.0.0.1:8081;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
        }

        location ~ ^/metube/.*\.(css|js)$ {
            proxy_pass http://127.0.0.1:8081;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
        }
</pre>
<p>主站 <a style="border-bottom: 1px dashed #000000; cursor: help;" title="PHP 是一种流行的开放原始码脚本语言。官方正式名称为“PHP: Hypertext Preprocessor”的递归缩写。" href="http://www.webopedia.com/TERM/P/PHP.html" rel="external">PHP</a> 脚本都是远程调用 CDN 的 css|js，没有本地的，所以没出问题。至少这样暂时能用。 <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_neutral.gif' alt=':neutral:' class='wp-smiley' />  <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_neutral.gif' alt=':neutral:' class='wp-smiley' />  <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_neutral.gif' alt=':neutral:' class='wp-smiley' /> </p>
<p>没找到问题的根本！ <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/299.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Nginx 用 SNI 分流传递客户端 IP 的 问题</title>
		<link>https://www.quakemachinex.com/blog/298.html</link>
		<comments>https://www.quakemachinex.com/blog/298.html#comments</comments>
		<pubDate>Sun, 03 Oct 2021 14:42:58 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/298.html</guid>
		<description><![CDATA[SNI 分流后获取客户端 IP 一般通过 proxy_protocol 来实现，但分流后的某些程序不能识别 proxy_protocol 怎么办？比如我的 DoH 服务器要 IP 地址，但某木头马并不支持，我开启 proxy_protocol 这马就死了。
]]></description>
			<content:encoded><![CDATA[<p><a style="border-bottom: 1px dashed #000000; cursor: help;" title="服务器名称指示（英语：Server Name Indication，缩写：SNI）是TLS的一个扩展协议[1]，在该协议下，在握手过程开始时客户端告诉它正在连接的服务器要连接的主机名称。这允许服务器在相同的IP地址和TCP端口号上呈现多个证书，并且因此允许在相同的IP地址上提供多个安全（HTTPS）网站（或其他任何基于TLS的服务），而不需要所有这些站点使用相同的证书。它与HTTP/1.1基于名称的虚拟主机的概念相同，但是用于HTTPS。" href="https://zh.wikipedia.org/wiki/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%8D%E7%A7%B0%E6%8C%87%E7%A4%BA" rel="external">SNI</a> 分流后获取客户端 IP 一般通过 proxy_protocol 来实现，但分流后的某些程序不能识别 proxy_protocol 怎么办？比如我的 DoH 服务器要 IP 地址，但某木头马并不支持，我开启 proxy_protocol 这马就死了。</p>
<p>我们看代码片段，注意注释。</p>
<p>nginx.conf 主配置文件片段：</p>
<pre class="prettyprint">
stream {
    # 这里就是 SNI 识别，将域名映射成一个配置名
    map $ssl_preread_server_name $backend_name {
        我的域名.坑 web;
        马.我的域名.坑 马;
        # 域名都不匹配情况下的默认值
        default web;
    }
    # 转发到 web 服务器
        upstream web {
        server 127.0.0.1:444;
    }
    # 转发到 马 前置服务器
        upstream 马 {
        server 127.0.0.1:446;
    }
    # 为 马 去除 proxy_protocol
    server {
        #nginx server 443 开启 proxy_protocol 后，分流后的所有服务也必须开启 proxy_protocol，否则会报错
        listen 127.0.0.1:446 proxy_protocol so_keepalive=on;
        proxy_protocol off; #然而，我们在这儿把 proxy_protocol 关闭掉，因为 马 不支持！这是关键
        proxy_connect_timeout 300s;
        proxy_timeout 300s;
        proxy_pass 127.0.0.1:445; #这就是 马 实际吃草的地方
    }

     # 监听 443 并开启 ssl_preread
     server {
         listen 443 reuseport;
         listen [::]:443 reuseport;
         proxy_pass $backend_name;
         ssl_preread on; #开启了分流
         proxy_protocol on; #开启了 proxy_protocol
    }
}
</pre>
<p>虚拟站点配置文件代码块，大致如下：</p>
<pre class="prettyprint">
server
{
     #nginx server 443 开启 proxy_protocol 后，分流后的所有服务也必须开启 proxy_protocol，否则会报错
    listen 127.0.0.1:444 ssl http2 reuseport proxy_protocol;
    #下面三行给反代的 DoH 服务器传递了客户端 IP
    set_real_ip_from 127.0.0.1;
    real_ip_recursive on;
    real_ip_header proxy_protocol;

    server_name 三达不溜.我的域名.坑 我的域名.坑;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /home/wwwroot/我的域名.坑;

    ssl_certificate /usr/local/nginx/conf/ssl/fullchain.cer;
    ssl_certificate_key /usr/local/nginx/conf/ssl/我的域名.坑_ssl.key;

    #反代 DoH 服务器
    location /dns-query {
        proxy_pass       http://127.0.0.1:8053/dns-query;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr; #我要，真实的，IP！
    }
</pre>
<p>差不多这样。 <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' />  <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' />  <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_cool.gif' alt=':cool:' class='wp-smiley' /> </p>
<p>来自 https://github.com/trojan-gfw/trojan/issues/433#issuecomment-692878138 的方法更加精妙：</p>
<pre class="prettyprint">
stream {
    log_format basic '$remote_addr - $remote_user [$time_local] '
                     '$protocol $status $bytes_sent $bytes_received '
                     '$session_time';
    map $ssl_preread_server_name $backend {
        trojan6.domain.com unix:/run/nginx-trojan-stream.sock;
        trojan.domain.com unix:/run/nginx-trojan-stream.sock;
        default 127.0.0.1:443;
    }
    server {
        listen unix:/run/nginx-trojan-stream.sock proxy_protocol;
        proxy_pass 127.0.0.1:8443;
    }
    server {
        listen 0.0.0.0:443;
        listen [::]:443;
        proxy_pass $backend;
        ssl_preread on;
        proxy_protocol on;
    }
}

http {
    log_format combined '$proxy_protocol_addr - $remote_user [$time_local] '
                        '"$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent"';
    server {
        listen 127.0.0.1:80 proxy_protocol;
        listen [::1]:443 ssl proxy_protocol;
        ...
    }
}
</pre>
<blockquote class="purecode"><p>
http 的 log_format 中，原来的将原来的 $remote_addr 替换成 $proxy_protocol_addr 就成了。</p>
<p>stream 中的第一个 server 就是为了接收带 proxy_protocol 的 stream，然后发出不带 proxy_protocol 的 stream 给 trojan。</p>
<p>另外，我用的是在 Ubuntu 20.04上 的 Nginx v.1.18.0，来自官方 apt 源的。
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/298.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>自建订阅转换 SUB-WEB 前端 + Subconverter 后端</title>
		<link>https://www.quakemachinex.com/blog/297.html</link>
		<comments>https://www.quakemachinex.com/blog/297.html#comments</comments>
		<pubDate>Tue, 28 Sep 2021 05:19:21 +0000</pubDate>
		<dc:creator>AvP</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">https://www.quakemachinex.com/blog/297.html</guid>
		<description><![CDATA[本文大部分内容来自 自行搭建Clash订阅转换平台 一文，感谢原作者。
预备工作：
首先需要在域名服务商解析两个域名，都是 A 记录
前端 我们使用 sub.mysite.com
后端 我们使用 sc.mysite.com
最好先]]></description>
			<content:encoded><![CDATA[<p>本文大部分内容来自 <a href="https://www.v2rayssr.com/sub-web.html">自行搭建Clash订阅转换平台</a> 一文，感谢原作者。</p>
<h3>预备工作：</h3>
<p>首先需要在域名服务商解析两个域名，都是 A 记录</p>
<p>前端 我们使用 sub.mysite.com</p>
<p>后端 我们使用 sc.mysite.com</p>
<p>最好先把 mysite.com 做好泛域名解析，例如：</p>
<blockquote class="purecode"><p>
apt install socat<br />
curl  https://get.acme.sh | sh<br />
acme.sh --set-default-ca  --server  letsencrypt<br />
export Namecom_Username=&quot;myname&quot;<br />
export Namecom_Token=&quot;fe9ckjdbnkjasd76dta7d7fb9b91a59c9&quot;<br />
acme.sh --issue --dns dns_namecom -d mysite.com -d *.mysite.com
</p></blockquote>
<h3>搭建Sub-Web前端</h3>
<h5>更新系统并安装 Node 与 Yarn</h5>
<p>依次运行下面四行代码，若是 CentOS 系统，请自行替换下面前两行命令中的 apt 为 yum</p>
<blockquote class="purecode"><p>
apt update -y<br />
apt install -y curl wget sudo nodejs npm git
</p></blockquote>
<p>服务器在国内的:</p>
<blockquote class="purecode"><p>
npm install -g cnpm --registry=https://registry.npm.taobao.org<br />
cnpm install -g yarn
</p></blockquote>
<p>服务器在国外的</p>
<blockquote class="purecode"><p>
npm install -g yarn
</p></blockquote>
<p>命令执行完毕以后，请运行下面的代码查询 Node 与 Yarn 是否安装成功，若是成功会返回版本号</p>
<blockquote class="purecode"><p>
node -v<br />
yarn --version
</p></blockquote>
<h5>下载并安装 Sub-Web</h5>
<p>拉取 sub-web 程序，并进入 sub-web 文件夹</p>
<blockquote class="purecode"><p>
git clone https://github.com/CareyWang/sub-web.git --depth=1<br />
cd sub-web
</p></blockquote>
<p>在项目目录中安装构建依赖项，构建的过程稍微有点长</p>
<blockquote class="purecode"><p>
yarn install
</p></blockquote>
<p>使用 webpack 运行 Web 客户端以进行本地开发。</p>
<blockquote class="purecode"><p>
yarn serve
</p></blockquote>
<p>到目前为止，浏览器访问 http://服务器ip:8080/ 应该可以进行前端 sub-web 的预览了。</p>
<h6>修改默认后端地址</h6>
<p>找到 VPS /root/src/sub-web/src/views/Subconverter.vue 文件</p>
<p>找到 257行 backendOptions:（写博客的时候是这行），替换后面的 <code>http://127.0.0.1:25500/sub?</code> 为 <code>https://suc.mysite.com/sub?</code></p>
<p>（注意两个地方：域名为你刚才准备的后端域名，是 https 而非 http）</p>
<h6>更换远程规则</h6>
<p>因为这个版本更新以后，规则方面很少，经常用到的一些经典的 ACL4SSR 的规则并没有集成，大家可以看看，若是有，就不需要这样操作。</p>
<p>VPS找到 /root/src/sub-web/src/views/Subconverter.vue 文件，找到 258行 <code>remoteConfig: [</code>，敲下回车，插入下面内容。</p>
<blockquote class="purecode"><p>
{<br />
            label: &quot;ACL4SSR&quot;,<br />
            options: [<br />
              {<br />
                label: &quot;ACL4SSR_Online 默认版 分组比较全 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_AdblockPlus 更多去广告 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_AdblockPlus.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_NoAuto 无自动测速 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoAuto.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_NoReject 无广告拦截规则 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoReject.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Mini 精简版 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Mini_AdblockPlus.ini 精简版 更多去广告 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_AdblockPlus.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Mini_NoAuto.ini 精简版 不带自动测速 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_NoAuto.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Mini_Fallback.ini 精简版 带故障转移 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_Fallback.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Mini_MultiMode.ini 精简版 自动测速、故障转移、负载均衡 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Full 全分组 重度用户使用 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Full_NoAuto.ini 全分组 无自动测速 重度用户使用 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_NoAuto.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Full_AdblockPlus 全分组 重度用户使用 更多去广告 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_AdblockPlus.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Online_Full_Netflix 全分组 重度用户使用 奈飞全量 (与Github同步)&quot;,<br />
                value:<br />
                  &quot;https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Netflix.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR 本地 默认版 分组比较全&quot;,<br />
                value: &quot;config/ACL4SSR.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Mini 本地 精简版&quot;,<br />
                value: &quot;config/ACL4SSR_Mini.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Mini_NoAuto.ini 本地 精简版+无自动测速&quot;,<br />
                value: &quot;config/ACL4SSR_Mini_NoAuto.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_Mini_Fallback.ini 本地 精简版+fallback&quot;,<br />
                value: &quot;config/ACL4SSR_Mini_Fallback.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_BackCN 本地 回国&quot;,<br />
                value: &quot;config/ACL4SSR_BackCN.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_NoApple 本地 无苹果分流&quot;,<br />
                value: &quot;config/ACL4SSR_NoApple.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_NoAuto 本地 无自动测速 &quot;,<br />
                value: &quot;config/ACL4SSR_NoAuto.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_NoAuto_NoApple 本地 无自动测速&amp;无苹果分流&quot;,<br />
                value: &quot;config/ACL4SSR_NoAuto_NoApple.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_NoMicrosoft 本地 无微软分流&quot;,<br />
                value: &quot;config/ACL4SSR_NoMicrosoft.ini&quot;<br />
              },<br />
              {<br />
                label: &quot;ACL4SSR_WithGFW 本地 GFW列表&quot;,<br />
                value: &quot;config/ACL4SSR_WithGFW.ini&quot;<br />
              }<br />
            ]<br />
          },
</p></blockquote>
<p>修改完毕以后，程序会自动更新，稍等然后再次刷新前端网页，会出现刚才添加的相关规则以及后端地址。</p>
<p>至此，我们的前端调试完毕，我们现在需要打包，生成一个发布目录。</p>
<p>首先停止调试程序，CTRL+C ，退出当前调试，然后执行下面的命令进行打包：</p>
<blockquote class="purecode"><p>
yarn build
</p></blockquote>
<p>执行以下打包命令，在 /root/src/sub-web 下面会生成一个 dist 目录，这个目录即为网页的发布目录。<br />
把这个目录下的文件全部拷贝到你之前发布网站的目录下，比如 /home/wwwroot/mysite:</p>
<blockquote class="purecode"><p>
cp -R /root/src/sub-web/dist/* /home/wwwroot/mysite
</p></blockquote>
<h3>反代详解：</h3>
<p>因为之前已经有主站，我们需要反代前端和后端这两个站点：</p>
<p>打开你的 nginx.conf 文件（根据系统不同位置不一样，用 <code>nginx -V</code> 查看 --conf-path= 找到这个文件），在 event 和 http 代码块中间插入 stream 块内容：</p>
<pre class="prettyprint">
...
events {
	worker<em>connections 768;
	# multi</em>accept on;
}

stream {

#这里就是 <a style="border-bottom: 1px dashed #000000; cursor: help;" title="服务器名称指示（英语：Server Name Indication，缩写：SNI）是TLS的一个扩展协议[1]，在该协议下，在握手过程开始时客户端告诉它正在连接的服务器要连接的主机名称。这允许服务器在相同的IP地址和TCP端口号上呈现多个证书，并且因此允许在相同的IP地址上提供多个安全（HTTPS）网站（或其他任何基于TLS的服务），而不需要所有这些站点使用相同的证书。它与HTTP/1.1基于名称的虚拟主机的概念相同，但是用于HTTPS。" href="https://zh.wikipedia.org/wiki/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%8D%E7%A7%B0%E6%8C%87%E7%A4%BA" rel="external">SNI</a> 识别，将域名映射成一个配置名，请修改自己的一级域名

map $ssl_preread_server_name $backend_name {
    mysite.com web;
    sub.mysite.com sub;
    sc.mysite.com sc;
    #域名都不匹配情况下的默认值
    default web;

}

#web 主站转发
upstream web {
    server 127.0.0.1:444;
}

#sub 前端转发
upstream sub {
    server 127.0.0.1:446;
  }

#sc 后端转发
upstream sc {
    server 127.0.0.1:447;
  }

#监听 443 并开启 ssl_preread
server {
    listen 443 reuseport;
    listen [::]:443 reuseport;
    proxy<em>pass $backend</em>name;
    ssl_preread on;
  }
}

http {
...
</pre>
<p>然后在对应的虚拟站点目录（一般是 nginx 配置目录下的 vhosts 目录 或者 conf.d 目录，lnmp 是 sites-enable 目录）建立两个新站点配置文件：</p>
<h6>sub.mysite.com.conf</h6>
<pre class="prettyprint">
server {
    listen 80;
    server_name sub.mysite.com;
    if ($host ~<em> &quot;sub.mysite.com$&quot;) {
    rewrite ^/(.</em>)$ https://sub.mysite.com/ permanent;
    }
}

server
{
    listen 127.0.0.1:446 ssl http2;
    server<em>name sub.mysite.com;
    ssl</em>certificate &#39;/root/cfg/ssl/fullchain.cer&#39;;
    ssl<em>certificate</em>key &#39;/root/cfg/ssl/mysite.com.key&#39;;
    ssl<em>protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl</em>prefer<em>server</em>ciphers   on;
    ssl<em>session</em>timeout &#39;64m&#39;;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/sub.mysite.com;

#禁止访问的文件或目录
location ~ ^/(.user.ini|.htaccess|.git|.svn|.project|LICENSE|README.md)
{
    return 404;
}
access_log off;

}
</pre>
<h6>sc.mysite.com.conf</h6>
<pre class="prettyprint">
server {
    listen 80;
    server_name sc.mysite.com;
    if ($host ~<em> &quot;sc.mysite.com$&quot;) {
    rewrite ^/(.</em>)$ https://sc.mysite.com/ permanent;
    }
}

server
{
    listen 127.0.0.1:447 ssl http2;
    server<em>name sc.mysite.com;
    ssl</em>certificate &#39;/root/cfg/ssl/fullchain.cer&#39;;
    ssl<em>certificate</em>key &#39;/root/cfg/ssl/mysite.com.key&#39;;
    ssl<em>protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl</em>prefer<em>server</em>ciphers   on;
    ssl<em>session</em>timeout &#39;64m&#39;;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/sc.mysite.com;

#反代后台
location /
{
    proxy_pass http://127.0.0.1:25500;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
}

#禁止访问的文件或目录
location ~ ^/(.user.ini|.htaccess|.git|.svn|.project|LICENSE|README.md)
{
    return 404;
}
access_log off;

}
</pre>
<p>由于我们之前申请的是泛域名证书，所以这里的虚拟站点都可以用一样的证书和密匙。</p>
<h3>SubConverter后台搭建</h3>
<p>下载并解压后端程序</p>
<blockquote class="purecode"><p>
cd /root/src<br />
wget https://github.com/tindy2013/subconverter/releases/download/v0.7.0/subconverter_linux64.tar.gz<br />
tar xvf subconverter_linux64.tar.gz
</p></blockquote>
<p>完成以后，在 /root/src 文件夹下会多出一个 subconverter 的文件夹，这个就是我们的后端程序</p>
<p>修改配置文件参数<br />
现在我们需要修改后端配置文件中的一些参数</p>
<blockquote class="purecode"><p>
cd subconverter<br />
cp pref.example.ini pref.ini
</p></blockquote>
<p>然后修改这个配置文件： /root/src/subconverter/pref.ini ，找到如下参数进行修改</p>
<blockquote class="purecode"><p>
api_access_token=123123dfsdsdfsdfsdf            #api 默认没开启，这里随意设置<br />
managed_config_prefix=https://suc.mysite.com  #设置成我们刚刚解析的后端域名<br />
listen=127.0.0.1                                #这里改成 127.0.0.1 进行反代
</p></blockquote>
<p>接下来我们需要创建一个服务，让 VPS 每次重启或是开机自动运行后端程序</p>
<blockquote class="purecode"><p>
systemctl edit subconverter --full --force
</p></blockquote>
<p>贴入以下内容，保存。</p>
<pre class="prettyprint">
[Unit]
Description=A API For Subscription Convert
After=network.target

[Service]
Type=simple
ExecStart=/root/src/subconverter/subconverter
WorkingDirectory=/root/src/subconverter
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
</pre>
<p>检查运行状态以及设置开机自启</p>
<blockquote class="purecode"><p>
systemctl enable --now subconverter<br />
systemctl status subconverter
</p></blockquote>
<p>到这里，后端也就搭建完毕了，因为之前已经做好反代，我们现在可以在浏览器里面访问我们的后端了 https://suc.mysite.com, 成功会返回 subconverter 版本号。</p>
<p>全文完。</p>
<p> <img src='https://www.quakemachinex.com/blog/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>https://www.quakemachinex.com/blog/297.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
