<?xml version="1.0" encoding="UTF-8"?><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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux &#8211; WilliamKyle&#039;s Home</title>
	<atom:link href="https://www.williamkyle.com.cn/archives/category/linux/feed" rel="self" type="application/rss+xml" />
	<link>https://www.williamkyle.com.cn</link>
	<description>不积跬步，无以至千里；不积小流，无以成江海。</description>
	<lastBuildDate>Fri, 08 Apr 2022 14:44:10 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.9.3</generator>
	<item>
		<title>Long time no update</title>
		<link>https://www.williamkyle.com.cn/archives/229.html</link>
					<comments>https://www.williamkyle.com.cn/archives/229.html#respond</comments>
		
		<dc:creator><![CDATA[WilliamKyle]]></dc:creator>
		<pubDate>Sat, 06 Oct 2012 04:55:05 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[随笔]]></category>
		<guid isPermaLink="false">http://www.williamkyle.com.cn/?p=229</guid>

					<description><![CDATA[好久没更新了，最近没少折腾东西，但是一直在折腾，木有写什么日志做一些保留神马的。最近信息没怎么梳理，只是在不停 &#8230; <a href="https://www.williamkyle.com.cn/archives/229.html" class="more-link">继续阅读<span class="screen-reader-text">Long time no update</span></a>]]></description>
										<content:encoded><![CDATA[
<p>好久没更新了，最近没少折腾东西，但是一直在折腾，木有写什么日志做一些保留神马的。最近信息没怎么梳理，只是在不停的尝试一些问题的解决办法，找到了些有用的资料也就是直接把网页快照下来，所以最近笔记软件没少用，像 EverNote、轻笔记、为知笔记等等，笔记软件用起来挺不错的，各有各的长处吧，但是对我来说主要就是存网页快照了。</p>



<p>最近工作的内容主要是搭环境，一个软件让我弄了快三个星期，简直恶心死了，主要是因为系统版本太低，导致需要解决各种依赖，往往是装一个软件需要 N 多依赖，装依赖的程序的时候发现依赖还需要依赖，然后就成了一棵很大的树了。最开始为了省事，拉下来一个源，结果发现系统版本太低，yum、apt-get 神马的都成浮云了，很多东西都不能安装到指定版本，而且系统还不能跨版本升级，强行升级直接不能开机╮(╯▽╰)╭</p>



<p>最后还是申请了一台机器装了个新版本的系统才搭完了这一套程序环境，我觉得老版本的系统得在这个月老老实实的一个个装依赖了，苦逼啊。。。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.williamkyle.com.cn/archives/229.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>关于 Discuz 在反向代理后用户 IP 的获取</title>
		<link>https://www.williamkyle.com.cn/archives/184.html</link>
					<comments>https://www.williamkyle.com.cn/archives/184.html#respond</comments>
		
		<dc:creator><![CDATA[WilliamKyle]]></dc:creator>
		<pubDate>Wed, 23 May 2012 17:42:54 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Discuz]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[反向代理]]></category>
		<guid isPermaLink="false">http://www.williamkyle.com.cn/?p=184</guid>

					<description><![CDATA[原本是 Discuz 的一个安全处理，这时候却给我带来了点麻烦。 CG 最近想给实验室弄个 BBS，于是默认选 &#8230; <a href="https://www.williamkyle.com.cn/archives/184.html" class="more-link">继续阅读<span class="screen-reader-text">关于 Discuz 在反向代理后用户 IP 的获取</span></a>]]></description>
										<content:encoded><![CDATA[
<p>原本是 Discuz 的一个安全处理，这时候却给我带来了点麻烦。</p>



<p>CG 最近想给实验室弄个 BBS，于是默认选了 Discuz，主机原来是 Windows 的，装了 Apache + MySQL + PHP，安装 Discuz 的时候还很正常，装完之后 CG 说上不去了。我打开页面，反应了半天还是没出来，于是打算在虚拟机里面装一个 Ubuntu，然后在 Ubuntu 下跑 Discuz。</p>



<p>装虚拟机神马的就不再说了，装完之后，突然想到一个问题，虚拟机的 IP 不能分到一个公网 IP，只能是虚拟网卡的内部 IP，这就意味着只有服务器能访问虚拟机。我知道 Nginx 是有反向代理的，然后上网一搜，发现 Apache 也可以实现反向代理，Apache 还确实很强大啊。于是马上修改 httpd.conf</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyPreserveHost On
ProxyPass /bbs/ http://192.168.77.80/bbs/
ProxyPassReverse /bbs/ http://192.168.77.80/bbs/
ProxyPass /bbs http://192.168.77.80/bbs</code></pre>



<p>检查语法没错，重启 Apache 服务打开网址一看，OK。装上一个 Discuz 测试一下，一切正常。然后看到 IP 我就纠结了，我在论坛上显示的 IP 都是 192.168.77.1，即服务器的 IP，怎么会这样子。这个万一要封 IP，岂不是都不能上了。于是开始郁闷了，在服务器上抓一下包，发现服务器的 Apache 反向代理是会转发连接用户的真实 IP 的，为什么在 Discuz 中不显示呢？开始我还以为是 Discuz 设计的问题，没有怎么仔细去查这个问题。突然，今天同学在实验室上网的时候，显示的登录 IP 是实验室的 IP，我就纳闷了，貌似寝室的 IP 地址 Discuz 不认啊。于是搜一下源代码，发现在 source/class/discuz/discuz_application.php 有如下片段</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="php" class="language-php">private function _get_client_ip() {
	$ip = $_SERVER['REMOTE_ADDR'];
	if (isset($_SERVER['HTTP_CLIENT_IP']) &amp;&amp; preg_match('/^([0-9]{1,3}.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	} elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#d{1,3}.d{1,3}.d{1,3}.d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
		foreach ($matches[0] AS $xip) {
			if (!preg_match('#^(10|172.16|192.168).#', $xip)) {
				$ip = $xip;
				break;
			}
		}
	}
	return $ip;
}
</code></pre>



<p>原来是 Discuz 认为寝室的 IP 段（10.xxx.xxx.xxx）算是伪造的 IP，好吧。把寝室的 IP 段限制删了，马上就正常了。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.williamkyle.com.cn/archives/184.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ubuntu 上搭建 PPTPD 的 VPN</title>
		<link>https://www.williamkyle.com.cn/archives/91.html</link>
					<comments>https://www.williamkyle.com.cn/archives/91.html#respond</comments>
		
		<dc:creator><![CDATA[WilliamKyle]]></dc:creator>
		<pubDate>Thu, 09 Feb 2012 08:05:19 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PPTPD]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VPN]]></category>
		<category><![CDATA[VPS]]></category>
		<guid isPermaLink="false">http://www.williamkyle.com.cn/?p=91</guid>

					<description><![CDATA[这个主机是在 BuyVM 买的 VPS，装的是 Ubuntu，折腾一年多了，下面把以前用 pptpd 搭建 V &#8230; <a href="https://www.williamkyle.com.cn/archives/91.html" class="more-link">继续阅读<span class="screen-reader-text">Ubuntu 上搭建 PPTPD 的 VPN</span></a>]]></description>
										<content:encoded><![CDATA[
<p>这个主机是在 BuyVM 买的 VPS，装的是 Ubuntu，折腾一年多了，下面把以前用 pptpd 搭建 VPN 的流程记录一下。</p>



<p>安装 pptpd</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">apt-get install pptpd</code></pre>



<p>配置 pptpd</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">vi /etc/pptpd.conf 
#去掉 localip 192.168.0.1 remoteip 192.168.0.234-238,192.168.0.245 前面的 #</code></pre>



<p>配置 ppp</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">vi /etc/ppp/options 
ms-dns 8.8.8.8 
vi /etc/ppp/chap-secrets 
#依次添加 用户名、服务器、密码、IP</code></pre>



<p>打开转发</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">vi /etc/sysctl.conf 
#去掉 net.ipv4.ip_forward=1 前面的 #</code></pre>



<span id="more-91"></span>



<p>设置路由</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 服务器 IP</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.williamkyle.com.cn/archives/91.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>一些常用到的 Bash 小语句</title>
		<link>https://www.williamkyle.com.cn/archives/40.html</link>
					<comments>https://www.williamkyle.com.cn/archives/40.html#respond</comments>
		
		<dc:creator><![CDATA[WilliamKyle]]></dc:creator>
		<pubDate>Thu, 09 Feb 2012 07:57:48 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash Shell]]></category>
		<guid isPermaLink="false">http://www.williamkyle.com.cn/?p=40</guid>

					<description><![CDATA[以后的工作将会与 Linux 打交道了，所以脚本必须得会用，这篇文章记录一下常用的一些 Bash 语句，以方便 &#8230; <a href="https://www.williamkyle.com.cn/archives/40.html" class="more-link">继续阅读<span class="screen-reader-text">一些常用到的 Bash 小语句</span></a>]]></description>
										<content:encoded><![CDATA[
<p>以后的工作将会与 Linux 打交道了，所以脚本必须得会用，这篇文章记录一下常用的一些 Bash 语句，以方便自己查阅。</p>



<h5>检测当前脚本运行用户是否具有 root 权限</h5>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">#!/bin/bash
if [ $(id -u) != "0" ]; then
	echo "Sorry, you must run this as root. You can cry sudo " $0
	exit 1
else
	echo "You are root"
fi
</code></pre>



<h5>按照当前日期组织文件名</h5>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="bash" class="language-bash">$(date +%Y%m%d).log
#Tips: 在用于 crontab 的计划任务时，由于% 在 crontab 里面有其他的意义，所以必须转义
$(date +\%Y\%m\%d).log</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.williamkyle.com.cn/archives/40.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
