军哥LNMP一键包安装自有SSL证书教程

背字根

军哥的LNMP一键包非常好用,也是我最喜欢的网站环境一键安装包。军哥的LNMP不只是Nginx,也支持Apache和LNMPA。

安装命令:

wget http://soft.vpser.net/lnmp/lnmp1.7.tar.gz -cO lnmp1.7.tar.gz && tar zxf lnmp1.7.tar.gz && cd lnmp1.7 && ./install.sh lnmp

以上命令安装Nginx环境,需要其他环境只需修改命令末尾的lnmp即可。

安装的过程中会提示是否安装证书,如果安装环境时没有选择安装SSL证书,可以使用以下命令补安装:

lnmp ssl add

安装过程参考:

[[email protected]]# lnmp ssl add
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Please enter domain(example: www.lnmp.org): www.beizigen.com
 Your domain: www.beizigen.com
Enter more domain name(example: lnmp.org *.lnmp.org): beizigen.com
 domain list: beizigen.com
Please enter the directory for domain www.beizigen.com: /home/wwwroot/www.beizigen.com
Allow Rewrite rule? (y/n) y
Please enter the rewrite of programme, 
wordpress,discuzx,typecho,thinkphp,laravel,codeigniter,yii2 rewrite was exist.
(Default rewrite: other): wordpress
You choose rewrite: wordpress
Allow access log? (y/n) y
Enter access log filename(Default:www.beizigen.com.log): 
You access log filename: www.beizigen.com.log
Enable PHP Pathinfo? (y/n) n
Disable pathinfo.
1: Use your own SSL Certificate and Key
2: Use Let's Encrypt to create SSL Certificate and Key
Enter 1 or 2: 1
Please enter full path to SSL Certificate file: /usr/local/nginx/conf/ssl/www.beizigen.com.crt
Please enter full path to SSL Certificate Key file: /usr/local/nginx/conf/ssl/www.beizigen.com.key
Test Nginx configure file......
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......

Nginx环境的SSL证书只有两个文件,一个后缀.crt,另一个后缀.key,上传到/usr/local/nginx/conf/ssl目录里即可。

我在安装的时候忘了我本地电脑保存的是Apache证书,怎么也安装不上,重新下载Nginx的证书后还是安装不上,此时需要删除配置文件重新安装:

rm -f /usr/local/nginx/conf/vhost/www.beizigen.com.conf

证书安装成功后配置HTTP跳转到HTTPS,编辑配置文件,添加:

server{  
	listen 80;
	server_name www.beizigen.com beizigen.com;
	return 301 https://$server_name$request_uri;
	location ~ / {
		index index.html index.php index.htm;
	}
}
个赞
扫码关注背字根

一个热爱Web开发的大男孩