nginx 支持PATH_INFO 的配置文件

如果下面的配置不对,请参考 thinkphp-pathinfo-nginx.html

 location ~ \.php {
        fastcgi_pass   127.0.0.1:9000;
        set $path_info "";
        set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {                     
        set $real_script_name $1;
        set $path_info $2;
        }
        fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;

        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param SERVER_SOFTWARE nginx;
        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_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param REQUEST_URI $request_uri;
        fastcgi_param DOCUMENT_URI $document_uri;
        fastcgi_param DOCUMENT_ROOT $document_root;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        # PHP only, required if PHP was built with --enable-force-cgi-redirect
        #fastcgi_param REDIRECT_STATUS 200;
    }

关于最近网络攻击防护的总结

一些服务器出问题,如服务器死机,如网站瘫痪,如被挂木马

整体思路是 如果正在攻击的服务器,就查看当前的 webserver 的log ,根据特征进行屏蔽

有的是 user-agent 一致 有的是 ip 一致,有的是 refer 一致

apache的相应设置可以做如下调整

BrowserMatchNoCase 特征1 bad_bot
BrowserMatchNoCase 特征2 bad_bot
Order Deny,Allow
Deny from env=bad_bot

可以写到 .htaccess 或者配置文件里面
关于特征字串有几点要说的 就是括号和加号 需要加\ 斜线
比如
"Mozilla/5.0 \(compatible; Googlebot/2.1; \+http://www.google.com/bot.html\)" 
才可以
同样也可以用rewrite 方法来对付这些
RewriteCond %{HTTP_USER_AGENT} "特征串1"
RewriteRule ^(.*)$ http://127.0.0.1
RewriteCond %{HTTP_USER_AGENT} "特征串2"
RewriteRule ^(.*)$ http://127.0.0.1
用的参数很多
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond

针对对特定user-agent 的apahce,nginx攻击的防护

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} “^特征字符串正则表达式$”
RewriteRule ^(.*)$ http://127.0.0.1

 

nginx 的配置如下

if ( $http_user_agent = “特征串”) { return 444; };
或者
if ( $http_user_agent ~* “特征串”) { return 444; }

注意特征串如果这正则情况下  斜线 / 括号 () 都是要加斜线的

 

centos 下 mplayer ffmpeg x264 等的安装方法

类youbutu 系统需要linux服务器里面支持mplayer 来把各类音视频文件转换为flv ,mplayer 里面的mencoder 调用ffmpg的方法实现,下面介绍安装方法

首先安装yasm

安装yasm
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar zxvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install

安装git
yum -y install git

安装mplay
wget http://www.mplayerhq.hu/MPlayer/releases/mplayer-export-snapshot.tar.bz2
tar jxvf mplayer-export-snapshot.tar.bz2
cd mplayer-export-2013-03-15
./configure
make
make install

安装x264
git clone git://git.videolan.org/x264.git
cd x264
./configure -enable-shared -prefix=/usr
make && make install

安装 mplayer

wget http://www.mplayerhq.hu/MPlayer/releases/mplayer-export-snapshot.tar.bz2
tar jxvf mplayer-export-snapshot.tar.bz2
cd mplayer-export-XXXXXXXXXX
./configure –enable-x264 –extra-libs=”-lx264″
make
make install

安装ffmpeg

下面这个地址很好 https://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide

nginx的ecshop伪静态配置

nginx 配置 ecshop 伪静态
if (!-e $request_filename)
{
rewrite "^/index\.html" /index.php last;
rewrite "^/category$" /index.php last;
rewrite "^/feed-c([0-9]+)\.xml$" /feed.php?cat=$1 last;
rewrite "^/feed-b([0-9]+)\.xml$" /feed.php?brand=$1 last;
rewrite "^/feed\.xml$" /feed.php last;
rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;
rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3 last;
rewrite "^/category-([0-9]+)-b([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2 last;
rewrite "^/category-([0-9]+)(.*)\.html$" /category.php?id=$1 last;
rewrite "^/goods-([0-9]+)(.*)\.html" /goods.php?id=$1 last;
rewrite "^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/article_cat-([0-9]+)-([0-9]+)(.*)\.html$" /article_cat.php?id=$1&page=$2 last;
rewrite "^/article_cat-([0-9]+)(.*)\.html$" /article_cat.php?id=$1 last;
rewrite "^/article-([0-9]+)(.*)\.html$" /article.php?id=$1 last;
rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2&page=$3 last;
rewrite "^/brand-([0-9]+)-c([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2 last;
rewrite "^/brand-([0-9]+)(.*)\.html" /brand.php?id=$1 last;
rewrite "^/tag-(.*)\.html" /search.php?keywords=$1 last;
rewrite "^/snatch-([0-9]+)\.html$" /snatch.php?id=$1 last;
rewrite "^/group_buy-([0-9]+)\.html$" /group_buy.php?act=view&id=$1 last;
rewrite "^/auction-([0-9]+)\.html$" /auction.php?act=view&id=$1 last;
rewrite "^/exchange-id([0-9]+)(.*)\.html$" /exchange.php?id=$1&act=view last;
rewrite "^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/exchange-([0-9]+)-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2 last;
rewrite "^/exchange-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1 last;
}

几乎所有支付通道的通知系统设计

简单一句话:

支付通道一般都有两种通知应用程序支付结果,一个叫PDT,一个叫IPN,

有些名称不一定叫这个,但是一般来说,原理是一致的,我们这里采用的是Paypal 的叫法

PDT 就是所谓的客户端通过网页返回付款数据

IPN 就是服务器之间的数据通知,一般来说IPN 有重复通知的,如果没有通知到,可能回发出多次通知

而且一般来说 IPN 速度要快过 PDT,这就是为什么有些支付后,显示订单已经被处理过的情况,其实我们认为,好的程序设计只要采用IPN通知来处理付款后的逻辑,这样比较安全,而网页返回部分逻辑可以用,仅仅查看本系统内的订单支付状态,根据订单支付状态来告知客户是否已经支付成功,就不必去处理更改订单状态的逻辑部分。当然,万一IPN通知出现了延迟,那么可以告知客户过一会再看,不必多次支付,免得对一个订单多次支付。

shopex 在nginx 环境开启伪静态

core/admin/controller/sale/ctl.tools.php
搜索 test_fake_html 后面加两行如下

 $svinfo->test_fake_html(false,$msg);
 $this->system->setConf('system.seo.emuStatic','true');
 return true;

nginx 的配置文件里面

location / { 
if (!-e $request_filename) { 
rewrite ^/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ /index.php?$1 last; 
# 下面这行也可以
#rewrite ^(.*)/(.+\.(html|xml|json|htm|php|jsp|asp|shtml))$ $1/index.php?$2 last;
         } 
} 
  

linux系统负载检查的思路

有时候客户会说服务器慢,综合来看就是负载变高了,一般情况下有几种可能

  1. 用户访问量确实增大
  2. 被攻击了
  3. 代码或者数据库更改造成索引丢失,或者代码未用到索引
  4. 硬件发热

首先通过 top 命令查看服务器中占用cpu比较重的进程,

如果发现是 mysql ,可以先在mysql > 命令行里面show full processlist; 查看是否有语句被lock,然后考虑
1)是否可以优化数据库索引
2) 是否可以找到相关php代码,
3)查找web服务器的日志,分析当前发生了什么,是否有恶意蜘蛛,或者采集,或者某些特征的访问,可以从web 配置里面屏蔽相应特征的访问,比如基于特定referer的访问,特定user-agent的访问

gzip 电信 联通 双线

双线服务器的电信联通侧的访问 居然不同 一侧是gzip了,另外一侧没有,好奇怪,除非是采用proxy方式的双线,可是查看确实又绑定了双ip,这就叫人摸不到头脑了,难道iis会针对不同ip 做gzip ,或者电信线路做了解压???

flv 自由拖动的几点注意事项,nginx 伪流服务器

编译 nginx 指出 flv module

参考 http://wiki.nginx.org/HttpFlvModule

./configure –with-http_flv_module  –其他参数

配置文件里面加入

location ~ \.flv$ {
  flv;
}

然后 如果是 jwplayer 的 播放器 ,注意参数

startparam: "start",

如果是 ckplayer 的播放器 ,注意参数

h:’0′,//播放http视频流时采用何种拖动方法,=0不使用任意拖动,=1是使用按关键帧,=2是按时间点,=3是自动判断按什么(如果视频格式是.mp4就按关键帧,.flv就按关键时间),=4也是自动判断(只要包含字符mp4就按mp4来,只要包含字符flv就按flv来)

q:”,//视频流拖动时参考函数,默认是start

 

参考资料

http://www.longtailvideo.com/support/jw-player/28855/pseudo-streaming-in-flash

 

nginx的discuzx伪静态

discuz X 的 nginx 伪静态规则

rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
if (!-e $request_filename) {
        return 404;
}

其他的建议去看
http://www.vpser.net/manage/nginx-rewrite.html

最近在64位系统上编译php上用–with-libdir=lib64

以前没注意到的,现在可以看下哦

./configure –prefix=/usr/local/php5 –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr –with-libdir=lib64

看到几篇文章,地址如下

http://www.07net01.com/linux/64weixitongxiabianyiPHPzhaobudaokuwenjianwenti_7518_1343998855.html

http://www.php-oa.com/2008/03/28/php-make.html

vncserver服务可以在系统引导时自动启动

关键一步:

vncserver服务可以在系统引导时自动启动. 但是需要进行设置才能使之正常自动启动.
首先,编辑/etc/sysconfig/vncservers文件,把使用VNC服务的用户添加到这个文件中,添加的内容如下例所示:
VNCSERVERS=”N:user”
此处N指VNC服务器所在的显示服务器编号。user指运行VNC的 用户。多个显示服务和用户之间可通过如下设置来指定:
VNCSERVERS=”N:user1 Y:user2″

来自

http://wfbwx.blog.hexun.com/31750918_d.html

nginx 针对一类特定referer 屏蔽,可能对某些攻击有效

一个客户服务最近受到攻击,通过查看nginx的log发现规律是 referer地址来自相同的字符串
于是乎用下面的屏蔽代码

if ($http_referer ~* "来源字串里面包含的特定字串"){return 403;}

下面是一些资料  详细英文的解释在 http://wiki.nginx.org/HttpCoreModule#location

~ 匹配,区分大小写
~* 不区分大小写的匹配
!~ 不匹配
!~* 不匹配
^~ 常用于location 语法中,后边是一个字符串。它的意思是,在这个字符串匹配后停止进行正则表达式的匹配。
如: location ^~ /images/,你希望对/images/这个目录进行一些特别的操作,如增加expires头,防盗链等,但是你又想把除了这个目录的图片外的所有图片只进行增加expires头的操作,这个操作可能会用到另外一个location,例如:location ~* \.(gif|jpg|jpeg)$,这样,如果有请求/images/1.jpg,nginx如何决定去进行哪个location中的操作呢?结果取决于标识符^~,如果你这样写:location /images/,这样nginx会将1.jpg匹配到location ~* \.(gif|jpg|jpeg)$这个location中,这并不是你需要的结果,而增加了^~这个标识符后,它在匹配了/images/这个字符串后就停止搜索其它带正则的location。
= 表示精确的查找地址,如location = /它只会匹配uri为/的请求,如果请求为/index.html,将查找另外的location,而不会匹配这个,当然可以写两个location,location = /和location /,这样/index.html将匹配到后者,如果你的站点对/的请求量较大,可以使用这个方法来加快请求的响应速度。
@ 表示为一个location进行命名,即自定义一个location,这个location不能被外界所访问,只能用于Nginx产生的子请求,主要为error_page和try_files。

参考资料来源

http://hi.baidu.com/jidongxx/item/de0f7e519980eeddd48bac38
http://ourlinux.blog.51cto.com/274624/850470

QQ截图20130418090527

 

另外 参见 /?p=198