作者归档:CD

在TL-WR703N上安装LEDE并扩展到U盘运行(Extroot)

更新

20170808 感谢@ian提醒,先修改fstab再复制overlay,就不会出现 fstab 恢复原始状态的状况。重新更改该部分内容。 20170706 在720N上,目前新版的LEDE使用f2fs格式化的U盘做exroot时,会出现类似如下的错误: mount: mounting /dev/sda1 on /mnt failed: Invalid argument mount: mounting /dev/sda1 on /mnt failed: I/O error 暂时解决办法是:windows上使用MiniTool Partition Wizard将U盘格式化为ext4格式。 相应的,制作固件时的命令改为: make image PROFILE=tl-wr703n-v1 PACKAGES="block-mount kmod-fs-ext4 kmod-usb-storage" 20170625 LEDE稳定发行版已于20170610更新为17.01.2,本文内容做相应修改。 20170430 LEDE稳定发行版已于20170418更新为17.01.1,本文内容做相应修改。 20170315 所有硬件版本的703N均可以按此方法扩展,但是强烈建议在可以刷入pepe2k不死uboot的703N上进行操作,理论上包括:v1.0-v1.6,以及v1.7(Dec. 2012 (FW build 121204))。 20170222 延迟1周后,LEDE第一个正式版的固件和软件包终于出现在了LEDE官方的下载库中,具体版本号是:17.01.0-r3205-59508e3官方网页暂时仍显示为Current Release - LEDE 17.01.0-rc2,但是应该很快会更新。按正式版重新整理里此文档,但不管是releases版还是snapshots,此文档均适用。 20170212 在无luci的情况下,设置PPPoE和无线桥接的方法可以参考这里20170205 LEDE目前已经放出了发行版的时间表,并已公布了第一个预览版 17.01.0 RC1。 17.01.0最终版将于2017年2月15公布。

说明

说明放在前面,以免浪费你的宝贵时间或可能破坏掉你的路由器: 1.不死uboot 因为只要有了不死uboot,就可以保证只要在uboot中刷入任何固件都不会导致变砖,所以我建议折腾的基础是建立在能刷入不死uboot的703N上。目前理论上可以方便的刷入pepe2k的不死uboot的703N硬件版本为:v1.0-v1.6,以及v1.7(Dec. 2012 (FW build 121204))。尽管事实上,如果想刷,任何版本的703N(包括April 2014 (3.17.1 Build 140120 Rel.56593n))都可以按此法进行扩展,只是个别703N--特指April 2014 (3.17.1 Build 140120 Rel.56593n)--因为不能方便的写入不死uboot,在操作的过程中存在变砖的可能性,尽管有一些硬件DIY可以救,但是这种情况是应该而且可以避免的。LEDE文档说支持的是703N V1。我这个背面铭牌上印的是:Ver:1.6,并操作成功;所以,我不清楚其他版本的情况; 2.这不是一个完全手把手的教程,只是记录自己折腾的过程,因此对于从没有折腾过OpenWrt的人来说,将会面对很多细节问题,一个小问题也许就会卡住你好几天的时间,甚至破坏了你的703N; 3.如果你想折腾,请务必读完全文再决定是否动手; 4.动手之前,请务必备份好网络配置文件(/etc/config/下的network,wireless,firewall),我假设你之前成功折腾了OpenWrt,不过,你折腾过OpenWrt,这些保不保存也无所谓了; 5.如果你对在没有luci(网页版的管理界面)的情况下如何配置网络完全不了解,我劝你动手之前还是要三思。 4.本文亦适用于TL-WR720N。

TL-WR703N只有4M闪存,如果想要安装官方稳定发行版(Stable Release,带luci),不管是OpenWrt还是LEDE,目前能成功配置USB扩展(Extroot)的最新版本是barrier_breaker 14.07

作为OpenWrt的Reboot项目,LEDE已运行多时。半年多了,第一个正式版已经发布,但目前只有此外每日更新的为snapshot版(该版本默认不带luci)。因闪存空间不足以安装扩展所需的软件,LEDE官方稳定发行版(Stable Release)和其开发快照版(Development Snapshot)都是无法扩展到U盘(Extroot)的。但是LEDE和OpenWrt一样,同样提供了一个固件构建程序包(imagebuilder),可以将扩展U盘所需软件直接打包进固件当中,避免了使用opkg安装这些文件出现的空间不足问题,从而成功实现Usb扩展。因为是采用官方工具自己构建,所以对那些使用别人打包的软件心存芥蒂的人来说,是个不错的选择。此外imagebuilder并非从头编译固件,只是相对简单的打包(make),因此不会耗费太多硬件资源和时间。

本文主要参考:
https://lede-project.org/docs/user-guide/extroot_configuration

1 Extroot的背景知识:

LEDE固件将所支持设备的内部存储划分为两部分,一部分高度压缩且只读(/),另一部分可写(/overlay)。LEDE(OpenWrt)通过linux内核的功能可以在表现形式上将这两部存储合并起来,使得对应用程序来说,只感觉到一个总的可读写的存储空间。
Extroot,则是在这两者之外,通过外置U盘等再添加一个外部的(/overlay),在启动时接替了(mounted over)内部的(/overlay)工作,从而实现扩展。还有个好处是,外部(/overlay)接替内部(/overlay)工作,并不彻底覆盖掉或破坏内部的(/overlay),只是运行于其上,这就意味着当外接U盘损坏或移除后,仍然可以通过内部的(/overlay)部分启动,恢复到开启Extroot前的状态。

2 实现步骤

2.1 所需的条件

64位的linux系统(运行在虚拟机中的也可以)
选择正确的固件构建程序包(imagebuilder)
假设是一个u盘(当时折腾14.07时分了三个区

2.2 建立工作目录

mkdir lede-703n
cd lede-703n

2.3 获取正确的imagebuilder

2.3.1 对于正式版:

2.3.1.1 在LEDE的下载库中找到703N所在的文件夹,并找到相关文件
https://downloads.lede-project.org/releases/17.01.2/targets/ar71xx/generic/

tl-wr703n-v1-squashfs-factory.bin
sha256sum: 6989535e198c7d250fcf39a4cf46e74a6230a0a40d2b5c66c22f290101e32c7c
tl-wr703n-v1-squashfs-sysupgrade.bin
sha256sum: 812ec41c9de2e94cb9fa1150f9662e050f4b2b21bd00ce328a8096f55aa1b458
lede-imagebuilder-17.01.2-ar71xx-generic.Linux-x86_64.tar.xz
sha256sum: 21635b5f9c8a21544fb46cb0fac714c4146d5da625105722867f45259fec07db

2.3.1.2 下载对应的imagebuilder:

wget https://downloads.lede-project.org/releases/17.01.2/targets/ar71xx/generic/lede-imagebuilder-17.01.2-ar71xx-generic.Linux-x86_64.tar.xz

wget出错就:

wget --no-check-certificate https://downloads.lede-project.org/releases/17.01.2/targets/ar71xx/generic/lede-imagebuilder-17.01.2-ar71xx-generic.Linux-x86_64.tar.xz

2.3.1.3 解压imagebuilder

xz -d lede-imagebuilder-17.01.2-ar71xx-generic.Linux-x86_64.tar.xz
tar -xvf lede-imagebuilder-17.01.2-ar71xx-generic.Linux-x86_64.tar
2.3.2 对于snapshots版:

2.3.2.1 在LEDE的下载库中找到703N所在的文件夹,并找到相关文件
https://downloads.lede-project.org/snapshots/targets/ar71xx/generic/

tl-wr703n-v1-squashfs-factory.bin
tl-wr703n-v1-squashfs-sysupgrade.bin
lede-imagebuilder-ar71xx-generic.Linux-x86_64.tar.xz

2.3.2.2 下载对应的imagebuilder:

wget https://downloads.lede-project.org/snapshots/targets/ar71xx/generic/lede-imagebuilder-ar71xx-generic.Linux-x86_64.tar.xz

wget出错就:

wget --no-check-certificate https://downloads.lede-project.org/snapshots/targets/ar71xx/generic/lede-imagebuilder-ar71xx-generic.Linux-x86_64.tar.xz

2.3.2.3 解压imagebuilder

xz -d lede-imagebuilder-ar71xx-generic.Linux-x86_64.tar.xz
tar -xvf lede-imagebuilder-ar71xx-generic.Linux-x86_64.tar

2.4 安装make所需的依赖

2.4.1 若是CentOS/RHEL
yum install subversion git gawk gettext ncurses-devel zlib-devel openssl-devel libxslt unzip
yum group install "Development Tools"
2.4.2若是Debian/Ubuntu
apt-get install subversion build-essential libncurses5-dev zlib1g-dev gawk git ccache gettext libssl-dev xsltproc unzip

2.5 打包固件

2.5.1 进入imagebuilder工作目录:
cd lede-imagebuilder-*
2.5.2 获取703N的打包参数PROFILE:tl-wr703n-v1。
make info
...
tl-wr703n-v1:
    TP-LINK TL-WR703N
    Packages: kmod-usb-core kmod-usb2
...
2.5.3 打包并获取固件
make image PROFILE=tl-wr703n-v1 PACKAGES="block-mount kmod-fs-f2fs kmod-usb-storage mkf2fs f2fsck"

打包很快完成,在bin/targets/ar71xx/generic/下可以找到已经打包好的固件。

ls ./bin/targets/ar71xx/generic/

17.01.2正式版:

lede-17.01.2-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin
lede-17.01.2-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin

snapshots版:

lede-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin
lede-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin

2.6 刷入固件

网线连接703N,强烈推荐在不死uboot中刷入sysupgrade固件。

2.7 扩展到U盘(Exroot)

2.7.1 更改root密码

安装好固件后,等指示灯稳定后,用puyyt连接路由器 192.168.1.1,首先是更改root密码

passwd
2.7.2 查看挂载情况
block info
/dev/mtdblock2: UUID="9fd43c61-c3f2c38f-13440ce7-53f0d42d" VERSION="4.0" MOUNT="/rom" TYPE="squashfs"
/dev/mtdblock3: MOUNT="/overlay" TYPE="jffs2"
/dev/sda1: UUID="fdacc9f1-0e0e-45ab-acee-9cb9cc8d7d49" VERSION="1.4" TYPE="ext4"
/dev/sda5: VERSION="1" TYPE="swap"
/dev/sda6: UUID="fffaa123-1234-5678-abcd-1234abcd5678" VERSION="1.7" MOUNT="/mnt/sda6" TYPE="ext4"

这里借用了原文的信息来说明情况。可见已经成功挂载U盘,三个区是:sda1、sda5、sda6。
sda1是为Extroot准备的,sda5是swap,sda6后续可以作为aria2和samba等文档存储区。

2.7.3 将U盘的第一个区sda1和第三个区sda6格式化为f2fs格式
mkfs.f2fs /dev/sda1
mkfs.f2fs /dev/sda6

f2fs格式是为闪存设计的,u盘和ssd建议为f2fs格式。

2.7.4 自动修改文件系统(fstab)信息:
block detect > /etc/config/fstab; \
sed -i s/option$'\t'enabled$'\t'\'0\'/option$'\t'enabled$'\t'\'1\'/ /etc/config/fstab; \
sed -i s#/mnt/sda1#/overlay# /etc/config/fstab; \
cat /etc/config/fstab;

此时自动配置好并显示挂载情况:

config 'global'
        option  anon_swap       '0'
        option  anon_mount      '0'
        option  auto_swap       '1'
        option  auto_mount      '1'
        option  delay_root      '5'
        option  check_fs        '0'

config 'mount'
        option  target  '/overlay'
        option  uuid    'fdacc9f1-0e0e-45ab-acee-9cb9cc8d7d49'
        option  enabled '1'

config 'swap'
        option  device  '/dev/sda5'
        option  enabled '1'

config 'mount'
        option  target  '/mnt/sda6'
        option  uuid    'fffaa123-1234-5678-abcd-1234abcd5678'
        option  enabled '1
2.7.5 复制/overlay到sda1
mount /dev/sda1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt

直接重启路由器:

reboot
2.7.6 重启后就可以查看到成功了:
df -h

2.8 后续

2.8.1想办法,把没有luci的路由器联网
如果之前备份过OpenWrt的网络配置文件,通过WinScp传回重启就可以了。
2.8.2安装必要组件:
opkg update
opkg install luci luci-i18n-base-zh-cn luci-theme-material
opkg install ...

注:
1.现在没必要安装luci-ssl,它使用的是一个自签名的证书;
2.不要在成功扩展后(Extroot)运行opkg upgrade,更不要通过luci或者putty更新固件,更新固件永远在uboot中进行。

在NETGEAR R6100上安装LEDE以及luci、material主题和中文语言包

更新

20170308
由于正式版发布,强烈建议使用正式版。但是如果仍然想安装Snapshot固件,那么该文档仍然适合你。
20170222
无luci的固件联网方法,可以参照这个帖子:
LEDE第一个正式版固件17.01.0已经可以下载。
如果R6100刷了LEDE后,感觉WIFI下载速度不够快,可以看看这个帖子:
NETGEAR R6100在LEDE中5GHz频段Wi-Fi的启用、设置与优化

OpenWrt的部分核心程序员认为OpenWrt不够开放透明,核心人员不够活跃又缺少合作,修补bug移植新功能速度慢,基础设施也不健全,所以他们决定重启试试(reboot),来建立一个更好的项目:LEDE

我折腾这个目前还处在Snapshot阶段(已足够稳定,未预装luci界面)并亟待发布稳定版的LEDE的原因很简单:
我暂时觉得material主题很漂亮。
因为OpenWrt的material主题处于snapshot中,未在Chaos Calmer 15.05.1中提供,即使可以强行安装成功,但会碰到opkg update失败(wget returned 5.)的情况。

简单记录下折腾过程:

折腾环境是:

假如路由器是NETGEAR R6100
路由器R6100通过网线连接移动宽带的光猫;
电脑通过WIFI连接R6100实现上网。

折腾思路是:

因为只有一根网线,且LEDE暂时未预装luci界面,只能通过putty操作。
1 安装LEDE;
2 通过这根网线连接电脑和LEDE路由器的LAN口,设置root密码,开启LEDE路由器的WIFI功能,顺带设置好LEDE路由器的PPPOE功能;
3 再通过这根网线将LEDE路由器的WAN口与移动光猫的LAN口连接,电脑通过WIFI和R6100连通,实现上网;
4 在电脑上通过WIFI和putty进一步设置。

折腾过程是:

1.安装LEDE

在LEDE下载目录中
https://downloads.lede-project.org/snapshots/targets/
找到R6100的固件。当前R6100正在运行OpenWrt,故下载sysupgrade固件即可。
https://downloads.lede-project.org/snapshots/targets/ar71xx/nand/lede-ar71xx-nand-r6100-squashfs-sysupgrade.tar

在OpenWrt的luci里: 系统-备份/升级中刷写新固件,此处注意要去掉“保留配置”的钩,之后刷写固件,切勿断电

2 有线连接电脑与LEDE路由器

刷入LEDE几分钟后,将电脑与LEDE路由器LAN口通过网线连接。LEDE路由器默认IP地址为192.168.1.1。将电脑有线网络设置ipv4自动获取,或者设置为192.168.1.2。此时在电脑上ping 192.168.1.1应该可以有回应了。

2.1 设置root密码

用putty通过 22端口登陆192.168.1.1,用户名为root,密码为空。见到欢迎界面后,即可设置root密码:

passwd
2.2 开启无线网络,设置PPPOE

2.2.1 开启WIFI

vi /etc/config/wireless

将config wifi-device ‘radio0’下的option disabled ‘1’改为

option disabled '0'

保存,并应用网络设置

/etc/init.d/network restart

稍等片刻,即可发现名为LEDE的可供连接的无线网络,密码为空。可在装好luci图形界面后再设置WIFI密码。

2.2.2 设置PPPOE

uci set network.wan.proto=pppoe
uci set network.wan.username=用户名
uci set network.wan.password=密码
uci commit

应用网络设置

/etc/init.d/network restart

2.2.3 更改LEDE路由器LAN的默认网关地址
(实测不更改此地址亦无问题,但强烈建议更改。否则通过浏览器登陆LEDE路由器luci界面的默认网关IP 192.168.1.1时,可能会出现移动光猫的登陆界面,因为移动光猫的网关IP默认也是192.168.1.1。)
此时最好将LEDE路由器LAN的默认网关设置为其他IP,本步及下文均设置为192.168.2.1。

vi /etc/config/network

将config interface ‘lan’区域下的option ipaddr ‘192.168.1.1’改为

option ipaddr '192.168.2.1'

保存,并应用新的网络设置

/etc/init.d/network restart

3 有线连接LEDE路由器和光猫,WIFI连接电脑和LEDE路由器

此时,用网线将LEDE路由器的WAN口与移动光猫的LAN口连接,电脑通过WIFI连接LEDE路由器,此时应该可以上网了。
putty登陆刚才设置好的LEDE路由器网关,192.168.2.1。

okpg update
opkg update

安装luci、material主题、中文语言包。

opkg install luci-ssl luci-theme-material luci-i18n-base-zh-cn

等待结束。
此时浏览器登陆192.168.2.1,顺利的话就可以看到material的luci界面了。
下一篇:NETGEAR R6100在LEDE中5GHz频段Wi-Fi的启用、设置与优化

升级 ESET 10 后更新病毒库时“找不到服务器”的解决办法

下载Eset 10的离线安装包,从Eset 9安装升级到Eset 10后,更新病毒库时遇到了“找不到服务器”的问题。

简单粗暴的解决办法:
在控制面板-卸载程序找到ESET,点击“更改”,然后选择“修复”即可。
或者彻底卸载后重新安装。

导致上述问题的可能原因是Eset 9的残余文件造成的。

附:Eset 10 简体中文离线安装包的官方下载地址
32位
64位
2016-11-21下载到的具体版本号是10.0.369.1。

在CentOS 6 上用谷歌身份验证器Google authenticator开启两步验证保护VPS的SSH登陆安全

通过Google Authenticator开启VPS在SSH登陆时的两步验证,可以有效对抗暴力破解。本文是在CentOS 6 64位系统的VPS上开启SSH登陆的两步验证。首先需要先在手机上安装好Google authenticator,常见的Android和IOS手机都是支持的。
主要参考:
Secure SSH with Google Authenticator Two-Factor Authentication on CentOS 7

详细步骤:

1 首先安装EPLE源:
Google authenticator位于EPLE源中,可以不用再去编译安装了。

yum install epel-release

2.安装Google authenticator

2.1 使用yum安装法:

yum install google-authenticator

同意导入GPG key即可:

Importing GPG key 0x0608B895:
Userid : EPEL (6) <epel@fedoraproject.org>
Package: epel-release-6-8.noarch (@extras)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]:y

2.2 使用rpm安装法:
有些小内存(比如64M)的VPS,会因为内存不足使得yum命令中途被killed。那么可以使用rpm 命令来手动安装Google authenticator。
下载:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/google-authenticator-0-0.3.20110830.hgd525a9bab875.el6.x86_64.rpm

安装:

rpm -ivh google-authenticator-0-0.3.20110830.hgd525a9bab875.el6.x86_64.rpm

3 配置Google authenticator

在VPS上运行如下命令:

google-authenticator

出现

https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@localhost.localdomain%3Fsecret%3DDUO5MSLICSFHYCMV
Your new secret key is: DUO5MSLICSFHYCMV
Your verification code is 036197
Your emergency scratch codes are:
22188647
15985270
10493468
55754566
92756123

Do you want me to update your "~/.google_authenticator" file (y/n)

在浏览器中打开网址:

https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@localhost.localdomain%3Fsecret%3DDUO5MSLICSFHYCMV

可以见到二维码,用手机的Google authenticator(身份验证器)程序扫描条形码,即会自动配置好。

如果扫描后手机未自动配置,则需要手动输入验证码(IOS)或输入提供的密钥(Android),在接下来的界面中,给账户起个名字,输入上面出现的密钥,如本例中的DUO5MSLICSFHYCMV,并默认基于时间的选项,确认即可。

secret key(DUO5MSLICSFHYCMV)和5个应急码(emergency scratch codes)保存到安全的地方,备用。

接下来四个选项,全部选择y即可,有兴趣的自己去研究。

Do you want me to update your "~/.google_authenticator" file (y/n) y

Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y

By default, tokens are good for 30 seconds and in order to compensate for
possible time-skew between the client and the server, we allow an extra
token before and after the current time. If you experience problems with poor
time synchronization, you can increase the window from its default
size of 1:30min to about 4min. Do you want to do so (y/n) y

If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting (y/n) y

4 修改pam设置

vi /etc/pam.d/sshd

顶部加入一行:

auth required pam_google_authenticator.so

最后看起来是这样的:

#%PAM-1.0
auth required pam_google_authenticator.so
auth required pam_sepermit.so
auth include password-auth
account required pam_nologin.so
...

这里有个坑,原文是将这一行加在最后一行之下(Add the following line to the bottom of line),结果登陆的时候不出现验证码的输入框。但是加在第二行就可以了,可能的原因是原作者用的是CentOS 7 系统。

5 修改ssh设置

vi /etc/ssh/sshd_config

定位到:

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

将no改成yes,改完后是这样的:

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication yes

6 重启ssh服务

service sshd restart

Stopping sshd: [ OK ]
Starting sshd: [ OK ]

7 退出SSH客户端,重新登陆进行验证,如下则成功:

login as: (此处输入登陆的用户名)
Using keyboard-interactive authentication.
Verification code:(这里输入手机端生成的验证码)
Using keyboard-interactive authentication.
Password:(这里输入登录的密码)

使用Let’s Encrypt的Certbot为ngxin生成ECDSA证书

更新

20170312 本文是以CentOS 6.8系统为基础的,而对于CentOS 7系统,certbot则包含在了EPEL源中,可以启用EPEL后直接安装,且命令也由certbot-auto改为了certbot,但是两者的命令参数是通用的。
256位的ECDSA密钥提供的安全性和3072位的RSA密钥相当,而对于大多数网站来说,2048位RSA密钥提供的安全性已经足够。ECDSA证书在算法和密钥长度上的优势可以提供更快的HTTPS访问速度,但浏览器和平台的支持度不如后者广泛。Nginx 1.11.0版本即开始支持ECDSA和RSA双证书配置,可以通过同时配置RSA证书来解决ECDSA证书的兼容性问题。以下内容主要是记录一下如何用Let's Encrypt官方推荐的Certbot生成ECDSA证书,亦为ECC证书。取得Certbot环境、全自动生成和更新RSA证书和注意事项,不再赘述。
主要参考:
Status of and instructions for EC certification generation using CertBot?

详细步骤:
1 进入Certbot工作目录

cd /etc/certbot/

2 生成ECDSA私钥
使用secp384r1曲线算法

openssl ecparam -genkey -name secp384r1 > ec.key

3 生成支持多域名的证书请求文件CSR
certbot目前只能以–csr的方式加载证书请求文件来生成ECDSA的证书,并且要求csr为der格式csr已支持der和pem格式
使用–csr时,要将需要申请证书的域名全部包含在csr中,如co1dawn.com和www.co1dawn.com,即需要生成多域名的CSR。
3.1 方法一(推荐直接使用方法二)

cp /usr/local/ssl/openssl.cnf /etc/certbot/
vi openssl.cnf

在[ req ]区块找到并去掉注释“#”:

req_extensions = v3_req # The extensions to add to a certificate request

在[ v3_req ] 加入如下内容:

subjectAltName = @alt_names
[ alt_names ]
DNS.1 = co1dawn.com
DNS.2 = www.co1dawn.com

修改后的样子:

[ v3_req ]

# Extensions to add to a certificate request

basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = co1dawn.com
DNS.2 = www.co1dawn.com

通过openssl使用-config参数生成多域名证书请求文件:

openssl req -new -sha384 -key ec.key -out ec-der.csr -outform der -config /etc/certbot/openssl.cnf

只需填入Common Name (e.g. server FQDN or YOUR name) []:co1dawn.com即可。前几项输入“.”,即为空;最后后两项留空即可。

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:.
State or Province Name (full name) [Some-State]:.
Locality Name (eg, city) []:.
Organization Name (eg, company) [Internet Widgits Pty Ltd]:.
Organizational Unit Name (eg, section) []:.
Common Name (e.g. server FQDN or YOUR name) []:co1dawn.com
Email Address []:.

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

3.2 方法二,更为简单,为推荐使用的方法

按需要做相应更改:

openssl req -new -sha384 -key ec.key -subj "/CN=co1dawn.com" -reqexts SAN -config <(cat /usr/local/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:co1dawn.com,DNS:www.co1dawn.com")) -outform der -out ec-der.csr

/usr/local/ssl/openssl.cnf为openssl编译安装时所在位置,根据实际情况更改,考虑到安全性和兼容性,请编译升级到最新版的openssl 1.0.2
3.3查看csr是否正确

openssl req -inform der -in ec-der.csr -noout -text
        ...
        Subject: CN=co1dawn.com
        ...
            X509v3 Subject Alternative Name:
                DNS:co1dawn.com, DNS:www.co1dawn.com
        ...

4 使用certbot生成ECDSA证书

./certbot-auto certonly --webroot -w /var/www/html/ -d co1dawn.com -d www.co1dawn.com --email "youremail@youremail.com" --csr "/etc/certbot/ec-der.csr"

具体命令的意义可参照之前的部分

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/certbot/0001_chain.pem. Your cert will expire on
   2016-11-29. To obtain a new or tweaked version of this certificate
   in the future, simply run certbot-auto again. To non-interactively
   renew *all* of your certificates, run "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

如不指定获取的证书存放目录时,默认放在cerbot程序所在目录,即/etc/certbot/。
生成三个证书:

0000_cert.pem  0000_chain.pem   0001_chain.pem

与certbot自动化生成并更新的RSA证书的对应关系是:

   0000_cert.pem   = cert.pem
   0000_chain.pem  = chain.pem
   0001_chain.pem  = fullchain.pem

在nginx中用到的是0000_chain.pem和0001_chain.pem,具体使用方法和前面一致

使用cloudflare的chacha20/poly1305补丁编译nginx,在ngxin中配置ECDSA和RSA双证书后,需要提供并提升ECDSA和chacha20/poly1305的优先级,ssl_ciphers可参考该文进行配置:

ssl_ciphers 'ECDHE+aECDSA+CHACHA20:ECDHE+aRSA+CHACHA20:ECDHE+aECDSA+AESGCM:ECDHE+aRSA+AESGCM:ECDHE+aECDSA+AES256+SHA384:ECDHE+aRSA+AES256+SHA384:ECDHE+aECDSA+AES256+SHA:ECDHE+aRSA+AES256+SHA';

5 局限性
5.1 OCSP stapling
目前Let’s encrypt使用的中间证书和RSA证书是同一个,因此如果同时使用certbot生成的ECDSA和RSA双证书时,在nginx的OCSP stapling配置部分的ssl_trusted_certificate用0000_chain.pem或者chain.pem都可以,目前这两个中间证书其实是同一个证书。官方预计在2017年3月31日前使用ECDSA算法的中间证书;
5.2 无法自动更新
现在certbot还不能像RSA证书那样智能化的生成并更新ECDSA证书,只能手动运行,而且再次运行时文件名会递增,需要更改文件名或在nginx中更改证书位置。
6 展望
Certbot的作者们早已在github上讨论直接生成双证书的可行性,那将大大简化配置双证书的复杂度,只是还没有具体的时间表。

启用数字PIN码快速解锁Chromebook

每次解锁Chromebook需要输入长长密码的历史即将成为过去,数字PIN码解锁功能已经登陆最新的Chrome OS dev分支,通过简单的数字PIN码就可以快速解锁Chromebook。数字PIN码解锁功能的添加和苹果为当年的iPhone添加复制粘贴功能给人的感觉相似:这么一个简单的功能为什么现在才有?

开启步骤是:

1 在地址栏输入:

chrome://flags/#quick-unlock-pin

快速定位到“快速解锁(PIN码)”,将“默认”设置为“已启用”,并重启Chromebook;

2 在地址栏输入:

chrome://md-settings

定位并点击“其他人”选项卡的“Screen lock”,
输入当前账户的密码后,在“Screen lock”中选中:
PIN码或密码
Setup PIN
两次输入PIN码后,确认。

3 在键盘上同时按“🔍+L”来测试。

几点说明:

1 Bugs:

1.1 常规“设置”下“不能确认”,如下:
点击chrome右上角的 ᎒ ,打开“设置”界面,在“其他人”选项下找到并点击:
Manage screen lock
输入账户密码后,在弹出的“Screen lock”中选中:
PIN码或密码
更改PIN
两次输入PIN码后,会出现无法确认的情况。

1.2 1.1步骤后有时候出现“不能关闭设置”的问题,解决办法是:点击键盘上的“概览模式”键,进入“概览模式”后关闭即可。

1.3 通过“chrome://md-settings”方式设置PIN码后,在不重启设备的情况下可以通过上面常规设置的方法更改PIN码,重启后还是会在最后一步出现上述的“不能确认”Bug。

2 PIN码的安全性问题:
Google之所以长时间不添加PIN码解锁方式,主要是基于安全性的考虑,4位数字PIN可以在18分钟内被破解。这次增加数字PIN码功能还没有见到Google更多的解释,最短4位,最长未知。
为了应对存在的安全问题,谷歌采取的办法是:输错3次PIN码,就需要输入账户密码。

3 需要提到一个人:François Beaufort
此人提前泄露了很多chrome功能,并于2013年被google招安,进而以“官方”的方式发布信息,此次PIN码功能是他在8月20日发出来的。

在CentOS 6 的LNMP服务器上部署Let’s Encrypt的SSL证书

Let's Encrypt官方推荐的客户端certbot自2016年2月3日#2344开始真正支持Python 2.6,而在此之前需要Python 2.7,盲目升级CentOS 6 自带的Python 2.6到2.7,可能导致yum不能使用等问题。certbot-auto作为certbot的自动化脚本可以自动安装依赖并自动配置运行环境,使得获取Let's Encrypt证书简便快捷。

系统要求:本文是在CentOS 6.8已经部署好LNMP的服务器上部署certbot-auto,需要拥有服务器的root权限,在certbot准备运行环境阶段需要的内存较大,实测至少需要240M以上的内存
主要参考:
Let’s Encrypt and Nginx
建立个人博客,推荐使用搬瓦工年付19.99美元KVM虚拟VPS,512M内存,10G硬盘,500G月流量。

详细步骤:

1 取得 certbot-auto

访问https://certbot.eff.org/,在

I'm using Software on System.

分别选择nginx,CentOS 6,将弹出安装使用的详细方法。
1.1 首先需要安装certbot所依赖的源

yum install epel-release

1.2 下载certbot,并赋予运行权限
假设将certbot放在 /etc/certbot/目录下,

mkdir /etc/certbot/ && cd /etc/certbot/
wget https://dl.eff.org/certbot-auto

赋予运行权限:

chmod +x ./certbot-auto

安装依赖并配置自动运行环境:

./certbot-auto

2 运行certbot-auto取得证书

对于正常运行的LNMP服务器来说,推荐使用–webroot插件来获取证书,可以不必停止nginx的服务器的正常运行,否则需要停止nginx。
2.1 取得证书的命令如下:

/etc/certbot/certbot-auto certonly --webroot -w /var/www/html/ -d co1dawn.com -d www.co1dawn.com --staple-ocsp --hsts --rsa-key-size 4096 -m youremail@youremail.com

上述命令详解如下:

certonly     生成证书,但不安装。对于nginx,安装模式目前支持尚不完善,我们自己在nginx中配置证书。

–webroot   借助正在运行nginx的网站所在目录来生成证书请求的临时文件,例:/var/www/html/.well-known/

-w               用来指定目前正常运行nginx的服务器的网站所在目录,假设为:/var/www/html/

-d                co1dawn.com,www.co1dawn.com是两个不同的域名,根据自己的实际情况填写。

–staple-ocsp   开启证书的OCSP验证。

–hsts             强制浏览器使用加密连接访问网站。

–rsa-key-size 4096  请求4096bit的证书,默认为2048位已经足够。

-m                 自己的电子邮件地址。

2.2 可能碰到的错误

If you're using the webroot plugin, you should also verify that you are serving files from the webroot path you provided.

需要在nginx的配置文件中SSL区块中指定certbot的临时目录

       location ~ /.well-known {
                   allow all; 
       }

2.3 生成的证书位置
顺利的话,会给出成功的提示,并显示证书所在位置。

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/co1dawn.com/fullchain.pem (success)

3 在nginx中配置证书

共获得一枚私钥,三枚证书,我们需要用到其中的三个,在nginx的配置文件中SSL区块配置如下L:

...
ssl on;
ssl_certificate /etc/letsencrypt/live/co1dawn.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/co1dawn.com/privkey.pem;

#Enable SSL stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/co1dawn.com/chain.pem;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
...

然后重启nginx服务:

service nginx restart

4 自动更新证书

90天的时间还是太短,因此需要自动更新证书
4.1 测试是否能自动更新

/etc/certbot/certbot-auto renew --dry-run

成功后有提示,但不会真正生成新的证书。
4.2 安装定时任务crontab

yum install -y vixie-cron

或者

yum install -y cronie

启动定时任务

service crond start

设crontab为开机自动启动

chkconfig crond on

4.3 将certbot-auto renew 加入定时运行

crontab -e

写入下列任务并保存退出:

14 06 * * * /etc/certbot/certbot-auto renew --post-hook "sudo service nginx reload" --quiet >> /var/log/certbot.log

如果出现

Unable to find post-hook command sudo in the PATH.
(PATH is /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

说明是以root权限运行的,可以去掉sudo,或者建立非root用户再运行。
这样每天早上6点14分,自动运行证书更新请求,并将运行日志记录在 /var/log/certbot.log,方便查看。

CentOS 6 系统LNMP环境下安装WordPress

Changes: 
2016-08-19
nginx-1.11.3 mainline或nginx-1.10.1, MariaDB 10.1.16, PHP 7.0.9,同样适用。
2016-05-04
nginx-1.9.15 mainline或nginx-1.10.0, MariaDB 10.1.13, PHP 7.0.5,同样适用。
2016-02-21
nginx 1.9.11, PHP 7.0.3,同样适用。
WordPress博客虽然越来越臃肿,但是与其功能不断丰富不无关系,目前是个人博客较好的选择。
本文介绍如何在CentOS 6系统的LNMP环境下安装WordPress。
说明:
1 本文从准备好的LNMP环境开始,成功的关键点在于要修改部分权限、用户名和用户组。
2 参考教程:
How To Install WordPress with nginx on CentOS 6
Nginx, PHP5, MySQL Support In CentOS 6.5

详细过程:
1 建立wordpress站点的数据库

登录MariaDB,密码是之前设置的

mysql -u root -p

下面举例的数据库、用户、密码分别为:“wordpress”、“wpuser”、“wppw”。可自定义。

建立名为“wordpress”的数据库

CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

建立名为“wpuser”的用户,并设置密码为“wppw”

CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppw';
Query OK, 0 rows affected (0.00 sec)

修复权限

GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)

exit,退出。

2 配置nginx与PHP

2.1 假设把网站文件放在 /var/www/wordpress 目录下:

mkdir -p /var/www/wordpress

2.1 配置站点文件的路径,并启用unix socket通信

vi /etc/nginx/conf.d/default.conf

如下修改,保存

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /var/www/wordpress;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php$is_args$args;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
         root /var/www/wordpress;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
         }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
}

“try_files $uri $uri/ /index.php$is_args$args;”,伪静态。

2.2 配置PHP,开启unix socket通信,并修改用户名和用户组

vi /etc/php-fpm.d/www.conf

2.2.1 修改unix socket通信,找到

listen = 127.0.0.1:9000

并修改为

listen = /var/run/php-fpm/php-fpm.sock

2.2.2 找到如下字段,去掉注释,并将nobody改为nginx,否则unix socket通信功能无效,nginx将无法与PHP连接。

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = nginx
listen.group = nginx
;listen.mode = 0660

2.2.3 找到如下字段,将user和group的apache改为nginx

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

修改user和group为nginx

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

如果忽略,会出现安装插件时需要输入用户名和密码的尴尬

Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

2.3 重启nginx、php-fpm

service nginx restart
service php-fpm restart

3 安装WordPress

3.1 下载并配置

cd /tmp && wget wordpress.org/latest.tar.gz

tar xvzf latest.tar.gz && cp -rf wordpress/* /var/www/wordpress/

cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

3.2 将WordPress连接至已经建好的数据库

找到数据库的配置字段,并按“1 建立wordpress的数据库”时所设置的数据库、用户名、密码进行修改:

vi /var/www/wordpress/wp-config.php

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'wppw');

3.3 修复网站所在文件夹的权限,

cd /var/www/

chown nginx:nginx * -R
usermod -a -G nginx nginx

如不进行此步,则在安装插件时,会出现和“2.2.3”相同的情况:

Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

3.4 用浏览器访问如下地址(假设站点IP为1.2.3.4,域名为www.urwp.com),并启动安装WordPress。

1.2.3.4/wp-admin/install.php

www.urwp.com/wp-admin/install.php

上一篇:CentOS 6 搭建LNMP服务器环境

CentOS 6 搭建LNMP服务器环境

更新: 
2017-05-26
1 CentOS 6支持时程的完整更新已于2016年第2季度结束,维护更新持续到2020-11-30,虽然还有3年多的时间,但请及时升级到CentOS 7。
2 如仍停留在CentOS 6,本教程仍然有效,可安装/升级至最新版的LNMP。

2017-05-25
1 更新至nginx 1.13.0,MariaDB 10.2.6,PHP 7.1.5。

2017-02-25
1 CentOS 7搭建LNMP请参考这篇文章。 

2016-08-19
1 nginx-1.11.3 mainline或nginx-1.10.1, MariaDB 10.1.16, PHP 7.0.9,同样适用。
2 目前centos 6 64位已升至6.8,同样适用。

2016-05-04
1 加入 nginx 的 mainline 和 stable 两个版本供安装选择,标题中总是选择mainline版,详见如下步骤。
2 经测试,该教程适用于nginx-1.9.15 mainline 或者 nginx-1.10.0 stable, MariaDB 10.1.13, PHP 7.0.5,按本教程新装则自动为最新版本;
3 如按本教程安装过老版本,可直接通过如下命令升级即可升级为最新版,无需额外步骤:

     yum update 2016-02-21 1 经测试,同样适用于nginx 1.9.11, PHP 7.0.3, 按本教程新装则自动为最新版本; 2 按本教程安装了nginx 1.9.10 PHP 7.0.2,可直接通过“yum update”命令升级即可,无需额外步骤。
以LNMP(Linux+nginx+MySQL+PHP)来搭建网络环境越来越流行,MariaDB也有逐渐取代MySQL的趋势。
说明:
1 本文以CentOS 6.7 64位系统为基础,安装nginx、MariaDB、PHP来搭建网络环境。
2 尽量采用yum方式,避免出现需要手动编写配置文件的棘手问题。
3 参考教程:
 How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6
 Ultimate Guide To Installing Nginx, MySQL, PHP5, PHP-FPM In CentOS 6.5

详细步骤:
1 更新系统是第一件事:

yum update -y

并查看系统版本:

head -1 /etc/issue

CentOS release 6.7 (Final)

2 配置源:
2.1 配置MariaDB官方源
首先需要定制MariaDB的官方源
选择合适的系统,系统版本,及MariaDB版本(最新是10.1)

CentOS > CentOS 6(64bit) > 10.1

从而获得CentOS 6 64位系统MariaDB 10.1版本的源地址,配置源方法

vi /etc/yum.repos.d/MariaDB.repo

填入如下内容

# MariaDB 10.1 CentOS repository list - created 2016-02-03 13:17 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

保存退出(按ESC键,输入:wq)。

2.2 配置PHP源
webtatic源更新较快,且其命名有自己的特色方式,可以避免与其他源的某些冲突:

rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

2.3 配置nginx官方源
官方nginx有两个版本,mainline和stable,即开发板和稳定版,区别是前者引入新特性但可能有新bug,后者足够稳定。事实上,两者均比较稳定,nginx的网站总是运行在mainline版上。
以下提供两个版本供选择,请选择其一,推荐使用mainline版。

2.3.1 mainline 版
nginx的mainline版

vi /etc/yum.repos.d/nginx.repo

系统是CentOS 6,故写入如下内容

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/6/$basearch/
gpgcheck=0
enabled=1

保存退出。

2.3.2 stable 版

vi /etc/yum.repos.d/nginx.repo

系统是CentOS 6,故写入如下内容

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

保存退出。

3 安装、启动服务及设置开机启动

3.1.1 安装MariaDB

yum install MariaDB-server -y

3.1.2 安装PHP

yum install php70w-fpm -y

安装扩展

yum install php70w-gd php70w-mysqlnd php70w-pdo php70w-mcrypt php70w-mbstring php70w-xmlrpc -y

3.1.3 安装nginx

yum install nginx -y

3.2 启动服务并设置开机启动

service nginx start

service mysql start

service php-fpm start

chkconfig --level 235 nginx on

chkconfig --level 235 mysql on

chkconfig --level 235 php-fpm on

4 配置

4.1 设置MariaDB

作为生来就是要接替MySQL的MariaDB,对MySQL的命令具有良好的兼容性。
此步主要是MariaDB的安全设置:

mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 

因为还未设置MariaDB的数据库,所以root密码也是空的,此处直接回车

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y

设置数据库的密码

New password: 

设置密码,设置一个你自己知道的密码。

Re-enter new password: 

再次输入密码

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

4.2 配置PHP

vi /etc/php.ini

找到

;cgi.fix_pathinfo=1

去掉注释,并将1改成0

cgi.fix_pathinfo=0

保存退出。

4.3 配置nginx

4.3.1 默认配置的情况下,直接用浏览器打开你的主机空间的IP地址或者域名(假设IP地址为1.2.3.4,域名为www.urwp.com,后面也会用到),就可以看到nginx的欢迎页面,说明nginx已经在工作了。

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

4.3.2 配置nginx,以支持PHP

vi /etc/nginx/conf.d/default.conf

修改前的默认配置是这样的:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

按下面内容修改,取消注释,并修改部分内容:

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

4.3.3 测试PHP是否正常运行

vi /usr/share/nginx/html/phpinfo.php

写入如下代码,并保存

<?php
phpinfo();
?>

重启nginx和PHP

service nginx restart
service php-fpm restart

再次访问你的主机地址或域名:

http://1.2.3.4/phpinfo.php

或者

http://www.urwp.com/phpinfo.php

可见到php相关信息,说明PHP和nginx已经配合工作了。
此时LNMP网络服务环境就已初步搭建了。
接下来,可以部署自己的网站,或者开个简单的博客,比如WordPress
下一篇:CentOS 6系统LNMP环境下安装WordPress

删除或修改“自豪地采用WordPress”

请启用子主题(child theme)后再进行主题的相关修改,主题更新时子主题所进行的修改不会被覆盖,利于维护。

“自豪地采用WordPress”是由主题目录下的footer.php控制的。

1 修改途径:
有两种途径可以修改,效果完全一致。
1.1 在WordPress仪表盘中,依次找到:
外观-编辑-主题页脚(footer.php)。
1.2 后台进入主题目录,然后:

vim footer.php

2 如何删除“自豪地采用WordPress”
通过上面的任一途径,直接删除如下字段即可:

<a href="<?php echo esc_url( __( 'https://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>

3 如何修改“自豪地采用WordPress”
3.1 举个例子,想改成如下的样式,并去掉“自豪地”:

© 2016 Coldawn. Powered by WordPress

只需将”© 2016 Coldawn.”直接加在上面提到的那串代码的前面,并将”Proudly”删除,把“powered”改成首字母大写“Powered”:

© 2016 Coldawn.<a href="<?php echo esc_url( __( 'https://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( 'Powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>

3.2 如果只想WordPress有链接,变成这样:

© 2016 Coldawn. Powered by WordPress

则把上面的代码中的“Powered by”提前到“© 2016 Coldawn.”后面,变成:

© 2016 ColPdawn. Powered by <a href="<?php echo esc_url( __( 'https://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>"><?php printf( __( ' %s', 'twentytwelve' ), 'WordPress' ); ?></a>

3.3 如果想添加更多内容,可复制第2步中删除的代码,直接粘贴到后面,按需要修改即可

https://wordpress.org/ 链接的网址 https://wordpress.org/
Semantic Personal Publishing Platform 鼠标指向目标时显示的浮动文字 优雅的个人发布平台
WordPress 用于显示站点名 WordPress

3.4 如果需要分两行显示,只需在需要分行的地方插入如下代码即可:

<br />