LNMP一键安装包使用Openresty替换Nginx
类别:建站知识   时间:01-13

安装 LNMP

首先安装screen,apt -y install screen 防止安装过程连接中断。

然后创建一个窗口,如screen -S lnmp

再来选择一个lnmp安装脚本,比如这里选择的是1.9版本:


 
  • #下载版:推荐海外VPS或空间较小用户使用
  • wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz -cO lnmp1.9.tar.gz && tar zxf lnmp1.9.tar.gz && cd lnmp1.9 && ./install.sh lnmp
  • #完整版:推荐国内VPS用户使用
  • wget http://soft.vpser.net/lnmp/lnmp1.9-full.tar.gz -cO lnmp1.9-full.tar.gz && tar zxf lnmp1.9-full.tar.gz && cd lnmp1.9-full && ./install.sh lnmp
  •  
  • #后续步骤参见https://lnmp.org/install.html
 
等待部署完成, 你就可以使用 lnmp 命令了

安装 Openresty

Openresty+Redis的缓存组合能绕过php,再通过Nginx SRcache拓展直达Redis。


 
  • #访问官网,页面下拉,选择对应的安装包
  • https://openresty.org/cn/download.html
  • #这里选择当前最新的1.21.4.1版本来演示(需要其它版本的请移步官网,替换对应的版本号)
  • wget https://openresty.org/download/openresty-1.21.4.1.tar.gz
  • #解压
  • tar -zxvf openresty-1.21.4.1.tar.gz
  • #进入目录
  • cd openresty-1.21.4.1
 
如果你的站点不打算使用CDN,那么可以使用下面的构建编译语句。

 
  • #开始手动编译,并添加两个模块
  • ./configure --with-http_stub_status_module --with-http_v2_module
  • #安装
  • make && make install
 
如果你决定使用CloudFlare的CDN,不妨再编译个模块:http_realip_module,这样能获取到访客的真实ip,而不是CloudFlare的ip地址。

 
  • #构建
  • ./configure --with-http_stub_status_module --with-http_v2_module --with-http_realip_module
  • #编译安装
  • make && make install
 

关于报错

上面的 ./configure 构建过程若有错误,那肯定是没有按步骤来先安装lnmp。此时可以直接使用 apt -y install make gcc libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev  安装一下,然后再重新执行相关构建命令。

查看模块

检查必须的模块是否安装正确,后续主要用到的4个模块:srcache-nginx-module 、redis2-nginx-module 、redis-nginx-module 、set-misc-nginx-module ,以及lnmp脚本命令需要用到的2个模块:http_stub_status_module 和http_v2_module 。查看指定模块命令:


 
  • #能输出以上6个模块即可。
  • /usr/local/openresty/nginx/sbin/nginx -V 2>&1 | grep 'srcache-nginx-module\|redis2-nginx-module\|redis-nginx-module\|set-misc-nginx-module\|http_stub_status_module\|http_v2_module' -o
 

替换Nginx为Openresty


 
  • nano /etc/init.d/nginx
  • #将原先的“/usr/local/nginx”替换为openresty的实际路径“/usr/local/openresty/nginx”
  • #改好就是:
  • NGINX_BIN='/usr/local/openresty/nginx/sbin/nginx'
  • CONFIG='/usr/local/openresty/nginx/conf/nginx.conf'
 

完成了之后,接下来还需要修改其它相关的文件。反正最终的效果就是要替换完nginx,还能照常使用lnmp的全部指令~

后续的4个操作(重要!)

 

1. 修改 /bin/lnmp文件


 
  • #用编辑器打开lnmp文件,路径为下面一行,如果是finalshell直接到该路径双击打开编辑就行
  • /bin/lnmp
  • #再利用编辑器搜索下面一行的内容,一般可以使用快捷键ctrl+f
  • /usr/local/nginx
  • #然后全部替换为
  • /usr/local/openresty/nginx
  •  
  • #ps:lnmp1.8版本替换下来正好有106处还是108忘记了。
 

2. 复制ngnx配置文件


 
  • #将Nginx原配置文件夹复制到Openresty的Nginx下
  • cp -r /usr/local/nginx/conf/* /usr/local/openresty/nginx/conf
  • #修改openresty下的nginx.conf配置文件
  • nano /usr/local/openresty/nginx/conf/nginx.conf
  • #往pid的路径中添加一个“openresty”子路径,改完最后的结果就是这样的:
  • pid /usr/local/openresty/nginx/logs/nginx.pid;
 

  2.1 修改ssl路径

* 如果是全新安装的lnmp,且没有使用该lnmp环境申请过ssl证书,那么无视即可。

* 判断的方式很简单,你只要看 /usr/local/acme.sh/account.conf 文件是否存在,没有直接无视就行了。

* 如果存在,则必须修改!


 
  • #编辑初始配置文件
  • nano /usr/local/acme.sh/account.conf
  • #将“/usr/local/openresty/nginx/conf/ssl”修改为openresty的ssl存放路径,改完就是:
  • CERT_HOME='/usr/local/openresty/nginx/conf/ssl'
 

3. 修改ngnix.service路径


 
  • #先停止lnmp的nginx
  • lnmp stop nginx
  • #编译ngnix服务
  • nano /etc/systemd/system/nginx.service
  • #再将里面的“/usr/local/nginx”全部替换为openresty的nginx路径,如:/usr/local/openresty/nginx
  • #改完之后是这样的:
  • PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
  • ExecStart=/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
  • ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload
  • #然后重载下配置
  • systemctl daemon-reload
 

4. 修改软连接


 
  • #将openresty的nginx链接到lnmp里的nginx,完成“替换”(重要!)。
  • ln -snf /usr/local/openresty/nginx/sbin/nginx /usr/bin/nginx
  • #最后启动nginx(openresty)
  • lnmp start nginx
  • #或者直接使用 lnmp restart 来重启lnmp也可以,反正怎么开心怎么来。
 

执行完成之后可以使用 nginx -V 或者 nginx -t 等相关命令查看是否成功替换为openresty。

 

至此,替换结束。你可以像以往一样使用lnmp的全部指令~

测试 openresty


 
  • #重启openresty的nginx
  • #方式一
  • lnmp nginx restart
  • #方式二
  • systemctl restart nginx
  • #方式三
  • /etc/init.d/nginx restart
 

可能用到的命令

 


 
  • #V是大写字母!判断是否编译安装http_stub_status_module模块
  • /usr/local/openresty/nginx/sbin/nginx -V
  • #修改nginx的ln软连接
  • ln -snf /usr/local/openresty/nginx/sbin/nginx /usr/bin/nginx
 

 
  • Usage: lnmp {start|stop|reload|restart|kill|status}
  • Usage: lnmp {nginx|mysql|mariadb|php-fpm|pureftpd} {start|stop|reload|restart|kill|status}
  • Usage: lnmp vhost {add|list|del}
  • Usage: lnmp database {add|list|edit|del}
  • Usage: lnmp ftp {add|list|edit|del|show}
  • Usage: lnmp ssl add
  • Usage: lnmp {dnsssl|dns} {cx|ali|cf|dp|he|gd|aws}
  • Usage: lnmp onlyssl {cx|ali|cf|dp|he|gd|aws}

智慧半岛,是一家专注于青岛网站建设青岛网站开发的青岛网络公司,Copyright ©2007-2019 Ebandao.Cn 版权所有 All Rights Reserved.(建议在1366x768以上的浏览器中访问)鲁ICP备08014496号

13153297890