<?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>Web &#8211; WilliamKyle&#039;s Home</title>
	<atom:link href="https://www.williamkyle.com.cn/archives/category/web/feed" rel="self" type="application/rss+xml" />
	<link>https://www.williamkyle.com.cn</link>
	<description>不积跬步，无以至千里；不积小流，无以成江海。</description>
	<lastBuildDate>Fri, 08 Apr 2022 14:59:37 +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>关于 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>博客安装笔记</title>
		<link>https://www.williamkyle.com.cn/archives/22.html</link>
					<comments>https://www.williamkyle.com.cn/archives/22.html#comments</comments>
		
		<dc:creator><![CDATA[WilliamKyle]]></dc:creator>
		<pubDate>Tue, 31 Jan 2012 11:31:41 +0000</pubDate>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[CKFinder]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[SyntaxHighlighter]]></category>
		<guid isPermaLink="false">http://www.williamkyle.com.cn/?p=22</guid>

					<description><![CDATA[之前博客的安装记录。 https://web.archive.org/web/20121105184732/h &#8230; <a href="https://www.williamkyle.com.cn/archives/22.html" class="more-link">继续阅读<span class="screen-reader-text">博客安装笔记</span></a>]]></description>
										<content:encoded><![CDATA[
<p>之前博客的安装记录。 <a href="https://web.archive.org/web/20121105184732/http://www.williamkyle.com.cn/" target="_blank" rel="noreferrer noopener">https://web.archive.org/web/20121105184732/http://www.williamkyle.com.cn/</a></p>



<p>以下是原文：</p>



<hr class="wp-block-separator"/>



<p>WordPress 的安装就不用怎么多说了。下载、解压、移动到你想要的目录，修改 owner，建数据库，安装就是的。</p>



<p>我主要讲一下插件的问题，我装的是<a rel="noopener" href="http://wordpress.org/extend/plugins/ck-and-syntaxhighlighter/" target="_blank"><strong>CK and SyntaxHighlighter</strong></a>这个插件，它综合了 CKEditor、CKFinder 以及 SyntaxHighlighter 三个软件，能够提供可视化编辑器、文件管理以及语法高亮。这个插件还是很不错的，至少很对我的胃口，然而这几个插件本身有着一些不足之处，所以得对它们进行一些修改。</p>



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



<h4>SyntaxHighlighter 的右上角的问号</h4>



<p class="has-text-align-center">&nbsp; &nbsp;&nbsp; <img style="width: 150px; height: 150px;" src="http://www.williamkyle.com.cn/wp-content/uploads/ckfinder/images/SyntaxHighlighter右上角问号.jpg" alt=""/>修改之前 VS 修改之后<img style="width: 150px; height: 150px;" src="http://www.williamkyle.com.cn/wp-content/uploads/ckfinder/images/SyntaxHighlighter右上角问号2.jpg" alt=""/></p>



<p>由于这个插件里的 SyntaxHighlighter 用的是 3.x 版本的，右上角会有一个问号出现，可以通过修改 css 文件让它不显示。</p>



<p>首先打开/wp-content/plugins/ck-and-syntaxhighlighter/syntaxhighlighter/styles/shCoreCk.css 找到&nbsp; &nbsp;&nbsp;</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="css" class="language-css">.syntaxhighlighter .toolbar {
  position: absolute !important;
  right: 1px !important;
  top: 1px !important;
  width: 11px !important;
  height: 11px !important;
  font–size: 10px !important;
  z–index: 10 !important;
}
</code></pre>



<p>&nbsp; &nbsp; 添加一个 display:none; 修改成</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="css" class="language-css">.syntaxhighlighter .toolbar {
  position: absolute !important;
  right: 1px !important;
  top: 1px !important;
  width: 11px !important;
  height: 11px !important;
  font–size: 10px !important;
  z–index: 10 !important;
  display:none:
}
</code></pre>



<h4>&nbsp;&nbsp;&nbsp;&nbsp;<br />SyntaxHighlighter 代码框右侧滚动条</h4>



<p>如上面所示，这个滚动条出现的很难看，同样修改 shCoreCk.css 文件，在第 54 行添加代码</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="css" class="language-css">.syntaxhighlighter table {
  margin: 1px 0 !important;
}
</code></pre>



<h4>&nbsp;SyntaxHighlighter 的自动换行</h4>



<figure class="wp-block-image"><img src="http://www.williamkyle.com.cn/wp-content/uploads/ckfinder/images/SyntaxHighlighter底下滚动条.jpg" alt=""/></figure>



<p>&nbsp;SyntaxHighlighter 3.x 版本貌似不会自动换行，同样可以通过修改 shCoreCk.css 文件让其自动换行</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="css" class="language-css">.syntaxhighlighter .line {
  white–space: pre !important;
} </code></pre>



<p>&nbsp; &nbsp; 修改成</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="css" class="language-css">.syntaxhighlighter .line {
  /*white-space: pre !important;*/
  white–space: pre–wrap;
  white–space: –moz–pre–wrap;
  white–space: –pre–wrap;
  white–space: –o–pre–wrap;
  word–wrap: break–word;
}
</code></pre>



<p>不过这样还是有问题的，它把折下去的行也算入行号内了，所以到后面，行号会缺少。</p>



<figure class="wp-block-image"><img src="http://www.williamkyle.com.cn/wp-content/uploads/ckfinder/images/SyntaxHighlighter断行.jpg" alt=""/></figure>



<p>这个在 SyntaxHighlighter 2.x 版本没有出现，但是 2.x 版本的复制会把行号也复制进去。</p>



<h4>CKFinder 的权限设置</h4>



<p>CKFinder 的后台首页是个 html 文件，可以直接访问，并创建文件夹、上传文件，危害甚大，所以必须处理。我的解决方案是在/wp-content/plugins/ck-and-syntaxhighlighter/ckfinder/config.php 文件里面添加 WordPress 的 wp-admin/admin.php 的引用，这样一来，就只有能登陆后台的用户使用这个功能了。</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="php" class="language-php">include(dirname(str_replace(", '/', __FILE__)) . '/../../../../wp-admin/admin.php');</code></pre>



<h4>CKFinder 的文件路径设置</h4>



<p>由于这个插件返回的文件路径使用的是相对路径，导致在后台编辑的时候不能显示的上传的文件，同样修改一下 config.php 即可，但是文件路径返回的是使用时的域名路径，所以如果修改了域名的话，估计都得修改了。</p>



<pre class="wp-block-code has-dark-gray-color has-text-color"><code lang="php" class="language-php">$baseUrl = 'http://' . $_SERVER["HTTP_HOST"] . '/wp-content/uploads/ckfinder/';
</code></pre>



<p>暂时就改了这么多，当然主题也改了一下，折腾了很久，最终由于 PhotoShop 水平有限，只是正式修改了一小部分，暂时就先这样吧，用空了再继续折腾。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.williamkyle.com.cn/archives/22.html/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
