Blog迁移到DigitalOcean的旧金山节点记
不知道现在还有没有人写博客,只知道很多曾经的链接都已经失效了,甚至域名都已经被废弃。而我还仍然想偶尔写点东西,抒发心情,因为这已经是我的一种生活方式了。
由于工作繁忙,这两天抽空把blog搬移到了DigitalOcean VPS上,选择DigitalOcean的原因其实很简单,因为性价比。五刀一个月的最基础版本的主机折合人民币也才一顿饭钱,在另外一个DigitalOcean VPS搭建梯子运行的不错,加上现在原本已经冷却下来的中文博客圈流量已经不高,因此性能方面已经足够使用。
一如既往的先安装VPS控制面板WDCP,但不幸的是经过测试无法运行,研究了半天不知道为什么。于是乎安装另一款AMH面板,很高兴经过测试可以正常运行,amh本身有绑定子域名(二级域名)到子目录的功能,但是是匹配的,比如bbs.xxxx.com绑定bbs目录,abc.xxxx.com绑定abc目录,我有个一级域名需要指向淘宝店铺,无法实现。
经过问度娘和自己研究,解决方法如下:
一、首先必须到面板里绑定域名并开启“二级域名绑定子目录”功能
绑定域名我就不截图了,可以绑定taobao.xxxx.com,abc.xxxx.com,也可以直接绑定泛域名*.xxxx.com
接下来开启“二级域名绑定子目录”功能
二、修改配置文件
可以ssh或者sftp找到/usr/local/nginx/conf/vhost
这个文件夹
找到对应网站的conf文件,比如xxxx.conf,vi编辑/usr/local/nginx/conf/vhost/xxxx.conf
或者用sftp软件编辑这个conf文件
增加下面的部分(作用是,当访问的域名是bbs.xxxx.com时候网站文件指向到/forum这个子目录)
if ( $host = 'bbs.xxxx.com' ){ set $subdomain "/forum"; }
例:
server { listen 80; server_name www.xxxx.com xxxx.com *.xxxx.com; #server_name end index index.html index.htm index.php; #index end set $subdomain ''; if ( $host ~* "(?:(w+.){0,})(b(?!wwwb)w+).b(?!(com|org|gov|net|cn)b)w+. [a-zA-Z]+" ) { set $subdomain "/$2"; } if ( $host = 'taobao.xxxx.com' ){ set $subdomain "/taobao"; } root /home/wwwroot/www.xxxx.com/web$subdomain; include rewrite/amh.conf; #rewrite end ....................以下配置文件省略
如果想绑定多个子域名(二级域名),以此类推
server { listen 80; server_name www.xxxx.com xxxx.com *.xxxx.com; #server_name end index index.html index.htm index.php; #index end set $subdomain ''; if ( $host ~* "(?:(w+.){0,})(b(?!wwwb)w+).b(?!(com|org|gov|net|cn)b)w+.[a-zA-Z]+" ) { set $subdomain "/$2"; } if ( $host = 'taobao.xxxx.com' ){ set $subdomain "/taobao"; } if ( $host = 'luntan.xxxx.com' ){ set $subdomain "/forum"; } root /home/wwwroot/www.xxxx.com/web$subdomain; include rewrite/amh.conf; #rewrite end ....................以下配置文件省略
三、验证生效
加好后保存退出
然后ssh执行下amh nginx restart或者到面板里重载一下nginx
看看是不是生效了