西部数码虚拟主机联系博主388元/5年

如何用LNMP添加虚拟主机建站

军哥的LNMP自发布以来一直广受好评,在今年六一也发布了LNMP1.9版本,新增了很多功能。具体可以查看博主以前的文章

使用LNMP添加一个网站也比较简单,一般我们常用lnmp vhost {add|list|del}来管理网站

root@imnian:~# lnmp vhost add #添加主机
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Please enter domain(example: www.lnmp.org): down.imnian.com #输入你的网站主域名
 Your domain: down.imnian.com
Enter more domain name(example: lnmp.org sub.lnmp.org): wget.imnian.com shell.imnian.com download.imnian.com #输入你的网站更多域名
 domain list: down.imnian.com wget.imnian.com shell.imnian.com download.imnian.com
Please enter the directory for the domain: down.imnian.com #输入你的网站目录
Default directory: /home/wwwroot/down.imnian.com: 
Virtual Host Directory: /home/wwwroot/down.imnian.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): #选择或者/默认伪静态规则
You choose rewrite: other
Enable PHP Pathinfo? (y/n) #是否启用pathinfo
Disable pathinfo.
Allow access log? (y/n) y #是否启用日志
Enter access log filename(Default:down.imnian.com.log): #设置日志名称
You access log filename: down.imnian.com.log
Enable IPv6? (y/n) n #是否启用IPv6
Disabled IPv6 Support in current Virtualhost.
Create database and MySQL user with same name (y/n) n #是否添加数据库
Add SSL Certificate (y/n) y #是否添加SSL
1: Use your own SSL Certificate and Key
2: Use Let's Encrypt to create SSL Certificate and Key
3: Use BuyPass to create SSL Certificate and Key
4: Use ZeroSSL to create SSL Certificate and Key
Enter 1, 2, 3 or 4: 1 #选择SSL添加方式/输入路径
Please enter full path to SSL Certificate file: /home/wwwroot/ssl/down.imnian.com.pem
Please enter full path to SSL Certificate Key file: /home/wwwroot/ssl/down.imnian.com.key
Using 301 to Redirect HTTP to HTTPS? (y/n) y #是否启用HTTP跳转HTTPS
Redirect http://down.imnian.com to https://down.imnian.com 

Press any key to start create virtul host...

添加完成输出

================================================
Virtualhost infomation:
Your domain: down.imnian.com
Home Directory: /home/wwwroot/down.imnian.com
Rewrite: other
Enable log: yes
Create database: no
Create ftp account: no
Enable SSL: yes
  =>Certificate file
IPv6 Support: Disabled
================================================
root@imnian:~# 

接下来就可以上传网站文件安装就行了,博主这里是搬家流年笔记下载站,所以就直接打包复制文件过来就行了,博主用到的是scp命令,具体使用方法可以查看这个文章

Linux命令-SCP-流年笔记
Linux命令-SCP-流年笔记
imnian的头像-流年笔记2个月前
05710
图片[1]-如何用LNMP添加虚拟主机建站-流年笔记

下载完成备份的文件后,解压在我的运行目录,然后删除Apache的伪静态配置文件.htaccess

tar -zxvf backup.tar.gz
#解压备份文件

接下来就是配置Nginx的伪静态规则了,LNMP的伪静态规则存放目录是/usr/local/nginx/conf/rewrite,在此文件下新建demo.conf,将Nginx伪静态规则存放在此文件保存,然后编辑网站配置文件/usr/local/nginx/conf/vhost/demo.conf,将include rewrite路径改为你新建的demo.conf,重启Nginx即可

图片[2]-如何用LNMP添加虚拟主机建站-流年笔记
/etc/init.d/nginx restart

搬家过来后发现网站部分CSS文件404不加载,经过检查发现是防跨目录设置问题,尝试删除.user.ini也无法删除,

需要执行chattr -i /网站目录/.user.ini才可以删除,删除后网站访问正常。

© 版权声明
THE END
喜欢就支持一下吧
点赞5赞赏 分享
评论 共2条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片