惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
V
Vulnerabilities – Threatpost
T
Tenable Blog
Forbes - Security
Forbes - Security
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
WordPress大学
WordPress大学
Latest news
Latest news
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
C
Cisco Blogs
博客园 - 聂微东
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
小众软件
小众软件
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
Security Latest
Security Latest
Y
Y Combinator Blog
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
L
LINUX DO - 最新话题
月光博客
月光博客
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
S
Security Affairs
P
Proofpoint News Feed
D
DataBreaches.Net
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG

网站相关 on 老刘博客

用lnmp安装thinkphp类的程序,文件夹没有权限 Django设置使用MySql的时候遇到的一些坑 RackNerd的2022年黑五活动 改用cloudcone的VPS 加入51la的优站计划 群晖安装trilium笔记web端不刷新的处理方法 开始使用Argon主题 更换为Dragon主题 Django部署在debian11服务器 试用荷兰的liteserverVPS python开发web程序,最好还是在Linux下 转到virmach 用input和字典初步实现我的一点小想法 几种Linux系统安装之后的体验 被百度劲风算法搞了 放弃百度小程序 crmeb商城后台标题修改方法 RSS终于又搞好了 RackNerd的6.18活动出来了 重新弄了下博客环境 试用urlos 捡漏注册了个l22.org的域名 把域名从阿里云转出到name.com的方法 nginx使用CDN后获取用户真实IP的方法 流金岁月启用新域名 停止使用RSS Feed 纯代码设置frp服务器 网站换了一台服务器 nodecache开通了中国直连线路 从宝塔面板换成oneinstack踩的一个坑 腾讯的CDN还是可以的 解决升级PHPmake: *** No rule to make target `install’. Stop.的问题 推荐篱落主机的香港VPS 网站被黑了? 换篱落的空间,用宝塔面板,CSRF校验失败 博客更换到阿里云香港轻量,并升级到wordpress5.3.0 再说说景安的服务 给7b2的主题加上评论回复功能 备忘,使用阿里云ossfs备份网站 记一次因为标点符号导致重装服务器的经历 利用cloudFlare的边缘计算workers实现外链转内链跳转 Godaddy可以用微信管理域名 wordpress自动升级到5.2.2 xshell6更新至0125 7b2主题每日签到不刷新的解决办法 推荐一款国外CDN——Nodecache,注册即送1T流量 上海云盾CDN简要设置指南 7b2主题添加百度是否收录及禁止非管理员访问后台 新浪SAE文件管理及防盗链的设置 配置WP-Mail-SMTP的技巧 只需三步,让你的wordpress在godaddy免费空间上完美呈现
博客web端改用apache
老刘 · 2020-12-30 · via 网站相关 on 老刘博客

试用了几天Cloudflare加racknerd的2h2g的小鸡,感觉还算差强人意。所以干脆就先把博客放这里算了,然后又突发奇想,其他的网站一直用的lnmp,为啥博客就不能用用lamp呢?况且apache在稳定性以及对php的支持等方面都比nginx要好,nginx的优势是轻便和并发能力强。其实对小博客来说,基本没有啥区别。

说折腾就折腾,编译安装apache,发现需要重新设置虚拟主机,设置的时候发现,不像nginx的时候,脚本提示把http301到https,什么www域名301到一级域名等,这些提示都没有。也没有设置伪静态的选项。网上查了一下,发现是几行代码就可以搞定的事情。

设置301跳转

在apache里设置301跳转很简单,只需要在.htaccess里添加代码就好了,老刘主要用到两个,一个是http跳到https,一个是www跳到一级域名。感觉比nginx要简洁一些,代码如下:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://tunan.org/$1 [R,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} !^iliu.org$ [NC]
RewriteRule ^(.*)$ http://iliu.org/$1 [L,R=301]

设置后才发现,设置和不设置没有啥区别,老刘用的cf,应该是在cf里设置了301到443接口了,至于wordpress伪静态的问题,也是很容易,直接到wordpress的后台,保存一下固定链接样式就行了,保存后在根目录里自动生成了.htaccess。代码如下:

# BEGIN WordPress
# 在“BEGIN WordPress”与“END WordPress”之间的指令(行)是
# 动态生成的,只应被WordPress过滤器修改。
# 任何对标记之间的指令的修改都会被覆盖。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

使用cloudflare后获取用户真实IP

由于apache已经自带mod_remoteip模块,所以只需按如下操作即可

#启用模块
vim /usr/local/apache/conf/httpd.conf
Include conf/extra/httpd-remoteip.conf
#添加如下内容
vim /usr/local/apache/conf/extra/httpd-remoteip.conf
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1/24
#CloudFlare IP Ranges
RemoteIPInternalProxy 103.21.244.0/22
RemoteIPInternalProxy 103.22.200.0/22
RemoteIPInternalProxy 103.31.4.0/22
RemoteIPInternalProxy 104.16.0.0/12
RemoteIPInternalProxy 108.162.192.0/18
RemoteIPInternalProxy 131.0.72.0/22
RemoteIPInternalProxy 141.101.64.0/18
RemoteIPInternalProxy 162.158.0.0/15
RemoteIPInternalProxy 172.64.0.0/13
RemoteIPInternalProxy 173.245.48.0/20
RemoteIPInternalProxy 188.114.96.0/20
RemoteIPInternalProxy 190.93.240.0/20
RemoteIPInternalProxy 197.234.240.0/22
RemoteIPInternalProxy 198.41.128.0/17 #你的CDN的IP,可以重复添加
#在httpd.conf中修改日志格式,在日志格式中加上%a,然后重启apache即可
LogFormat "%h %a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %a %l %u %t \"%r\" %>s %b" common
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combined

service httpd restar重启apache,然后去日志里看看,已经获得了真实IP。前连天灰常记忆博友说在cloudflare里设置一下也能显示真实IP,但是老刘没有找到这个设置,只好继续在网站上改了,网站上改还有一个好处是,这个方法不仅限于cloudflare,别的CDN也是适用的