博客搬家到BuyVM VPS

Posted by 冰河 at 01:07 8 Responses » 24,511 Views
032012

折腾独立博客除了内容外就是域名、主机和程序了。

域名从icyhe.com换成了binghe.org;程序从emlog换成了wordpress;主机从免费主机到美国主机再到北京BGP多线机房,最终搬到了国外的VPS。VPS是前几天BuyVM放货的时候抢到的,没想着搬,本打算VPS当SSH&VPN主机用,博客继续使用北京BGP多线机房,毕竟速度快还不用备案而且空间9月才到期。但是2012.4.2发生了一件不愉快的事导致博客被停掉。本来以为是技术问题,后来咨询下发现对方态度很恶劣,坚持让我搬走。空间都用了2年了,既然人家话都说到那份上,我也没再辩驳。

之前在123Systems买的128MB内存VPS使用lnmp.org的一键安装包死活通不过,但是在BuyVM上却出奇的顺利。于是修改域名A记录,绑定域名,上传文件&恢复数据库,一气呵成。

现在博客已经能访问了,欢迎大家批评指正~~~

UPDATE1:貌似出现好几次502了。看来内存确实不够用。

UPDATE2:把修改php-cgi的进程数由默认的5改成了3,貌似内存剩余40MB,之前是负十几MB。修改方法:

vi /usr/local/php/etc/php-fpm.conf

<valuename=”max_children”>3</value>

UPDATE3:vsftpd安装有点问题,程序是装上了,但是service没配置好。可以使用yum install vsftpd覆盖安装解决。

正式启用新域名binghe.org

Posted by 冰河 at 22:59 10 Responses » 14,498 Views
122010

其实一直想使用binghe的域名,无奈binghe.com、net、org和cn都被人注册了。后来想注册icehe域名,可是icehe.com和net同样被人注册了。于是注册了icyhe.com。今天无意查询whois,发现binghe.org未被注册,于是在Godaddy没有优惠的情况下,花了7.67$注册了这个域名。

接下来就是更换域名了。

首先按照原来域名的设置对新域名进行解析。因为两个域名绑定在同一空间,所以没有转移任何博客文件,只是修改了博客设置,然后用如下SQL语句将数据库中的链接进行了替换:

//把emlog_blog表里content,即全文的字段内容为icyhe.com的全部改为binghe.org。

update emlog_blog set content=REPLACE(content,’icyhe.com’,'binghe.org’)

//把emlog_blog表里excerpt,即摘要的字段内容为icyhe.com的全部改为binghe.org。

update emlog_blog set excerpt=REPLACE(excerpt,’icyhe.com’,'binghe.org’)

然后根据Google管理员工具的提示,对原有的域名进行301重定向。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^icyhe.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.icyhe.com$
RewriteRule ^(.*)$ http://www.binghe.org/$1 [R=301,L]

最后就是通知友情博客更新友情链接了,这是一个繁琐的苦力活。

最后不免唠叨几句:好域名都让猪拱了。上面几个被人占的域名,不是在域名投资商手里,就是个人闲置着。好像只有icehe.net在用。

Nginx多站点设置

Posted by 冰河 at 21:51 1 Response » 36,069 Views
十二 182009

方法一:多个.conf方法(优点是灵活,缺点就是站点比较多配置起来麻烦)

这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设:

IP地址: 202.55.1.100
域名1 example1.com 放在 /www/example1
域名2 example2.com 放在 /www/example2

配置 nginx virtual hosting 的基本思路和步骤如下:

把2个站点 example1.com, example2.com 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 example1.com.conf,example2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx

具体过程

下面是具体的配置过程:

1、在 /etc/nginx 下创建 vhosts 目录

mkdir /etc/nginx/vhosts

2、在 /etc/nginx/vhosts/ 里创建一个名字为 example1.com.conf 的文件,把以下内容拷进去

server {
        listen  80;
        server_name  example1.com www. example1.com;

        access_log  /www/access_ example1.log  main;

        location / {
            root   /www/example1.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

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

        location ~ /.ht {
            deny  all;
        }
}

3、在 /etc/nginx/vhosts/ 里创建一个名字为 example2.com.conf 的文件,把以下内容拷进去

server {
        listen  80;
        server_name  example2.com www. example2.com;

        access_log  /www/access_ example1.log  main;

        location / {
            root   /www/example2.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

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

        location ~ /.ht {
            deny  all;
        }
}

4、打开 /etc/nginix.conf 文件,在相应位置加入 include 把以上2个文件包含进来

user  nginx;
worker_processes  1;

# main server error log
error_log	/var/log/nginx/error.log ;
pid	/var/run/nginx.pid;

events {
	worker_connections  1024;
}

# main server config
http {
	include       mime.types;
	default_type  application/octet-stream;
	log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

	sendfile        on;
	#tcp_nopush     on;
    	#keepalive_timeout  0;
	keepalive_timeout  65;
	gzip  on;

	server {
        	listen         80;
        	server_name     _;
        	access_log      /var/log/nginx/access.log main;
        	server_name_in_redirect  off;
        	location / {
            		root  /usr/share/nginx/html;
            		index index.html;
        	}
	}

    # 包含所有的虚拟主机的配置文件
    include /usr/local/etc/nginx/vhosts/*;
}

5、重启 Nginx

/etc/init.d/nginx restart

方法二:动态目录方法(优点是方便,每个域名对应一个文件夹,缺点是不灵活)

这个简单的方法比起为每一个域名建立一个 vhost.conf 配置文件来讲,只需要在现有的配置文件中增加如下内容:

# Replace this port with the right one for your requirements
# 根据你的需求改变此端口
listen       80;  #could also be 1.2.3.4:80 也可以是1.2.3.4:80的形式
# Multiple hostnames seperated by spaces.  Replace these as well.
# 多个主机名可以用空格隔开,当然这个信息也是需要按照你的需求而改变的。
server_name  star.yourdomain.com *.yourdomain.com http://www.*.yourdomain.com/;
#Alternately: _ *
#或者可以使用:_ * (具体内容参见本维基其他页面)
root /PATH/TO/WEBROOT/$host;
error_page  404              http://yourdomain.com/errors/404.html;
access_log  logs/star.yourdomain.com.access.log;
location / {
root   /PATH/TO/WEBROOT/$host/;
index  index.php;
}
# serve static files directly
# 直接支持静态文件 (从配置上看来不是直接支持啊)
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log        off;
expires           30d;
}
location ~ .php$ {
# By all means use a different server for the fcgi processes if you need to
# 如果需要,你可以为不同的FCGI进程设置不同的服务信息
fastcgi_pass   127.0.0.1:YOURFCGIPORTHERE;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /PATH/TO/WEBROOT/$host/$fastcgi_script_name;
fastcgi_param  QUERY_STRING     $query_string;
fastcgi_param  REQUEST_METHOD   $request_method;
fastcgi_param  CONTENT_TYPE     $content_type;
fastcgi_param  CONTENT_LENGTH   $content_length;
fastcgi_intercept_errors on;
}
location ~ /.ht {
deny  all;
}

最后附另外一个二级域名匹配的方法

绑定域名
server_name *.abcd.com;
获取主机名
if ( $host ~* (.*).(.*).(.*))
{
set $domain $1;
}
定义目录
root html/abc/$domain/;
location /
{
root html/abcd/$domain;
index index.html index.php;

© 2009 - 2024 冰河的博客