海运的博客

Nginx下使用Awstats

发布时间:February 27, 2014 // 分类:日记分析 // No Comments

1.生成静态html:

/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.haiyun.me \
-lang=cn -dir=/home/wwwroot/awstats/

Nginx配置:

server {
  listen 80;
  server_name awstats.haiyun.me;
  access_log /var/log/nginx/awstats.log main;
  root /home/wwwroot/awstats;
  index index.html;

  # Restrict access
  #auth_basic "Restricted";
  #auth_basic_user_file /etc/awstats/htpasswd;

  location /css/ {
    alias /usr/local/awstats/wwwroot/css/;
  }

  location /icon/ {
    alias /usr/local/awstats/wwwroot/icon/;
  }

  location /js/ {
    alias /usr/local/awstats/wwwroot/js/;
  }
}

2.使用fcgi:

cd /usr/local/awstats/tools/nginx/
cp awstats-fcgi.php ../../wwwroot/cgi-bin/fcgi.php 
server {
  listen       80 default_server;
  server_name  _;

  access_log  /home/wwwlogs/access.log  main;

  root   /home/wwwroot/default;
  index  index.htm index.html index.php;

  location ~ ^/cgi-bin/.*\.(cgi|pl|py|rb) {
    gzip off;
    root   /usr/local/awstats/wwwroot;
    fastcgi_pass unix:/tmp/php-cgi.sock;
    include fastcgi.conf; 
    fastcgi_param SCRIPT_FILENAME    $document_root/cgi-bin/fcgi.php;
    fastcgi_param X_SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
    fastcgi_param X_SCRIPT_NAME      $fastcgi_script_name;
  }

  location /icon/ {
    alias /usr/local/awstats/wwwroot/icon/;
  }

  location /css/ {
    alias /usr/local/awstats/wwwroot/css/;
  }

  location /js/ {
    alias /usr/local/awstats/wwwroot/js/;
  }

}

字符转URL

发布时间:February 8, 2014 // 分类:PHP // No Comments

英文:

function tourl($str) {
  $str = preg_replace('/[^a-zA-Z0-9]+/', '-', $str);
  $str = trim($str, '-');
  return strtolower($str);
}

包含特殊字符:

function strtourl($str) {
  $str = htmlentities($str, ENT_QUOTES, "UTF-8");
  $str = preg_replace('/&([a-z]{1,2})(?:acute|lig|grave|ring|tilde|uml|cedil|caron);/i','\1',$str);
  $str = html_entity_decode($str, ENT_QUOTES, "UTF-8");
  $str = preg_replace('/[^a-z0-9]+/i', '-', $str);
  return strtolower($str);
}

Nginx rewrite 指令last break区别

发布时间:February 8, 2014 // 分类:Nginx // No Comments

nginx 的官方注释是这样的:

last
   stops processing the current set of ngx_http_rewrite_module directives followed by a search for a new location matching the changed URI;

break
   stops processing the current set of ngx_http_rewrite_module directives;

我们知道nginx运行分十一个执行阶段,上面说提到的ngx_http_rewrite_mode,可以理解为其中一个阶段-rewrite阶段。​

typedef enum {
    NGX_HTTP_POST_READ_PHASE = 0,
    NGX_HTTP_SERVER_REWRITE_PHASE,
    NGX_HTTP_FIND_CONFIG_PHASE,
    NGX_HTTP_REWRITE_PHASE,           //rewrite阶段在这里
    NGX_HTTP_POST_REWRITE_PHASE,
    NGX_HTTP_PREACCESS_PHASE,
    NGX_HTTP_ACCESS_PHASE,
    NGX_HTTP_POST_ACCESS_PHASE,
    NGX_HTTP_TRY_FILES_PHASE,
    NGX_HTTP_CONTENT_PHASE,
    NGX_HTTP_LOG_PHASE
} ngx_http_phases;

所以我们再来理解last与break的区别:
last: 停止当前这个请求,并根据rewrite匹配的规则重新发起一个请求。新请求又从第一阶段开始执行…
break:相对last,break并不会重新发起一个请求,只是跳过当前的rewrite阶段,并执行本请求后续的执行阶段…
我们来看一个例子:

server {
    listen 80 default_server;
    server_name dcshi.com;
    root www;

    location /break/ {
        rewrite ^/break/(.*) /test/$1 break;
        echo "break page";
    } 

    location /last/ {
         rewrite ^/last/(.*) /test/$1 last;
         echo "last page";
    }    

    location /test/ {
       echo "test page";
    }
}

请求:http://dcshi.com/break/*
输出: break page
分析:正如上面讨论所说,break是跳过当前请求的rewrite阶段,并继续执行本请求的其他阶段,很明显,对于/foo 对应的content阶段的输出为 echo “break page”; (content阶段,可以简单理解为产生数据输出的阶段,如返回静态页面内容也是在content阶段;echo指令也是运行在content阶段,一般情况下content阶段只能对应一个输出指令,如同一个location配置两个echo,最终只会有一个echo指令被执行);当然如果你把/break/里的echo 指令注释,然后再次访问/break/xx会报404,这也跟我们预期一样:虽然/break/xx被重定向到/test/xx,但是break指令不会重新开启一个新的请求继续匹配,所以nginx是不会匹配到下面的/test/这个location;在echo指令被注释的情况下,/break/ 这location里只能执行nginx默认的content指令,即尝试找/test/xx这个html页面并输出起内容,事实上,这个页面不存在,所以会报404的错误。

请求: http://dcshi.com/last/*
输出: test page
分析: last与break最大的不同是,last会重新发起一个新请求,并重新匹配location,所以对于/last,重新匹配请求以后会匹配到/test/,所以最终对应的content阶段的输出是test page;

假设你对nginx的运行阶段有一个大概的理解,对理解last与break就没有问题了。

原文:http://www.dcshi.com/?p=172

PowerDNS使用

发布时间:February 1, 2014 // 分类:DNS // No Comments

使用EPEL源可直接安装:

yum install pdns pdns-backend-mysql

添加MySQL数据库:

create database powerdns;
grant all privileges on powerdns.* to 'powerdns'@'localhost' identified by 'password';
use powerdns;
create table domains (
 id              INT auto_increment,
 name            VARCHAR(255) NOT NULL,
 master          VARCHAR(128) DEFAULT NULL,
 last_check      INT DEFAULT NULL,
 type            VARCHAR(6) NOT NULL,
 notified_serial INT DEFAULT NULL, 
 account         VARCHAR(40) DEFAULT NULL,
 primary key (id)
) Engine=InnoDB;

CREATE UNIQUE INDEX name_index ON domains(name);

CREATE TABLE records (
  id              INT auto_increment,
  domain_id       INT DEFAULT NULL,
  name            VARCHAR(255) DEFAULT NULL,
  type            VARCHAR(10) DEFAULT NULL,
  content         VARCHAR(64000) DEFAULT NULL,
  ttl             INT DEFAULT NULL,
  prio            INT DEFAULT NULL,
  change_date     INT DEFAULT NULL,
  primary key(id)
) Engine=InnoDB;

CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);

create table supermasters (
  ip         VARCHAR(64) NOT NULL, 
  nameserver VARCHAR(255) NOT NULL, 
  account    VARCHAR(40) DEFAULT NULL,
  PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;

将SQL信息添加到PowerDNS配置文件:

launch=gmysql
gmysql-host=localhost
gmysql-user=powerdns
gmysql-password=password
gmysql-dbname=powerdns

添加域名记录:

INSERT INTO domains (name, type) values ('example.com', 'NATIVE');
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values 
 (1,'example.com','SOA','localhost root@example.com 1',86400,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'example.com','NS','ns.example.com',86400,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'example.com','A','192.0.2.10',120,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'*.example.com','A','192.0.2.10',120,NULL,NULL);
insert  into `records`(`domain_id`,`name`,`type`,`content`,`ttl`,`prio`,`change_date`) values
 (1,'ns.example.com','A','192.0.2.10',120,NULL,NULL);

看看效果:

/etc/init.d/pdns monitor

PHP:

<?php
   try { 
      $dbo = new PDO('mysql:host=localhost;dbname=powerdns', 'powerdns', 'password');
   } catch (PDOException $e) { 
      $error = $e->getMessage();
      die("PDO Execute Error : ".$error."\n");       
   }
   $domain = 'www.haiyun.me';
   $sql = "SELECT `id` FROM domains WHERE NAME = \"$domain\"";
   $stmt = $dbo->query($sql);
   //var_dump($stmt);
   $result = $stmt->fetch(PDO::FETCH_ASSOC);
   var_dump($result);
   if ($result) {
      $id = $result['id'];
   } else {
      $sql = "INSERT INTO domains (name, TYPE) VALUES (\"$domain\", 'NATIVE')";
      $dbo->query($sql);
      $id = $dbo->lastInsertId();
   }
   $sql = "INSERT INTO `records` (`domain_id`, `name`, `TYPE`, `content`, `ttl`) VALUES (:id, :name, :type, :content, :ttl)";
   $stmt = $dbo->prepare($sql);    
   $stmt->execute(array(':id'=>$id, ':name'=>'a.'.$domain, ':type'=>'A', ':content'=>'192.168.1.1', ':ttl'=>'600')); 
   $stmt->execute(array(':id'=>$id, ':name'=>'b.'.$domain, ':type'=>'A', ':content'=>'192.168.1.1', ':ttl'=>'600')); 
?>

FastDFS配合FastDHT去重

发布时间:January 28, 2014 // 分类:Linux服务 // No Comments

FastDHT使用Berkeley DB为后端存储,安装:

wget https://fastdht.googlecode.com/files/FastDHT_v1.23.tar.gz
tar zxvf FastDHT_v1.23.tar.gz 
cd FastDHT
./make.sh C_INCLUDE_PATH=/usr/local/BerkeleyDB.6.0/include \
LIBRARY_PATH=/usr/local/BerkeleyDB.6.0/lib/
./make.sh install
mkdir -p /home/yuqing/fastdht
echo "/usr/local/BerkeleyDB.6.0/lib/" > /etc/ld.so.conf.d/db.conf
ldconfig

配置fastdht:

/etc/fdht/fdht_servers.conf
group_count = 2
group0 = 192.168.1.1:11411
group0 = 192.168.1.2:11411
group1 = 192.168.1.1:11411
group1 = 192.168.1.2:11411

配置fastdfs storage

/etc/fdfs/storage.conf 
check_file_duplicate=1
file_signature_method=hash
key_namespace=FastDFS
keep_alive=1
#include /etc/fdht/fdht_servers.conf

再次测试上传多次同个文件,重复上传的文件以链接方式保存。

分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
归档