怎样实现织梦dede搜索结果页按频道模型显示不同模板

大家知道怎样实现dede搜索结果页按频道模型显示不同模板吗,这问题网上看到不少朋友都在问,究竟怎样才能实现呢,下面是笔者总结的些方法:
dedecms门户模板的时候经常会有图片模型、文章模型、软件模型之类的,要是给搜索框加一个判定,例如搜索软件模型的时候显示一个模板,搜索文章模型的时候显示一个模板。
具体实现代码:
1 在head区域加入

1
2
3
4
5
6
7
8
9
10
<script language="javascript" type="text/javascript">
<!--
 function check(){
  if(document.formsearch.channeltype.value=="3")
  document.formsearch.action="{dede:field name='phpurl'/}/search_images.php"
  else
  document.formsearch.action="{dede:field name='phpurl'/}/search.php"
 }
-->
</script>

2 更改搜索代码

1
2
3
4
5
6
7
8
9
10
11
<form  name="formsearch" action="" *****ubmit="check();">
    <div class="form">
        <input type="hidden" name="kwtype" value="0" />
        <input name="q" type="text" class="search-keyword" id="search-keyword" value="{dede:global name='keyword' function='RemoveXSS(@me)'/}" />
        <select name="channeltype" id="channeltype" >
            <option value='1' selected='1'>新闻</option>
            <option value='3'>软件</option>
        </select>
        <button type="submit" class="search-submit">搜索</button>
     </div>
</form>

其中重点就是

1
2
3
4
<select name="channeltype" id="channeltype" >
    <option value='1' selected='1'>新闻</option>
    <option value='3'>软件</option>
</select>

关键设置:这里设置的按游戏模型搜索 1是文章模型 3是软件模型

3 复制serach.php 更名为 search_images.php
4 打开 search_images.php

1
require_once(DEDEINC."/arc.searchview.class.php");

更改为

1
require_once(DEDEINC."/arc.searchimg.class.php");

5复制 arc.searchview.class.php 更名为 arc.searchimg.class.php

6 打开 arc.searchimg.class.php
修改

1
2
 $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";
 $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search_images.htm";

核心的修改已经结束了,剩下的就是在search_images.htm这个模板里自由发挥了。
同理也可以实现按栏目type搜索显示不同风格的结果页得。

Nginx配置文件try_files语法及在WP Super Cache中的应用

try_files 是nginx0.6.36 后新增一个功能,用于搜索指定目录下的N个文件,如果找不到fileN,则调用fallback中指定的位置来处理请求。个人认为,作为nginx核心的内容,可以部分替代烦琐的rewrite功能,笔者把它用在wp super cache的rewrite重写中,也取得了不错的效果。

try_files
语法: try_files file1 [file2 … filen] fallback
默认值: 无
作用域: location

这个指令的作用就是可接收多个路径作为参数,当前一个路径的资源无法找到,则自动查找下一个路径,如当请求的静态资源不存在,就将请求fallback指定位置到后台服务器上进行动态处理。
简单的例子:

1
2
3
4
5
6
7
8
location / {
    try_files index.html index.htm @fallback;
}

location @fallback {
    root /var/www/error;
    index index.html;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
server {
    set $cache /wp-content/cache/supercache/$host;
        #wp-super-cache的路径
    listen 80;
    server_name _;
    location / {
        root /home/html/s0001/domains/$host;
        index index.php index.html;
                #直接调用gzip压缩后的html静态文件
        add_header Content-Type "text/html; charset=UTF-8";
        add_header Content-Encoding "gzip";
        try_files $cache/$uri/index.html.gz @proxy;
 
    }
    #所有静态文件都由nginx处理,并用gzip压缩输出
    location ~* \.(jpg|jpeg|png|gif|css|js|swf|mp3|avi|flv|xml|zip|rar)$ {
        expires 30d;
        gzip on;
        gzip_types  text/plain application/x-javascript text/css application/xml;
        root /home/html/s0001/domains/$host;
    }
    #找不到的文件都交给后端的apache处理了
    location @proxy {
        index  index.php index.htm index.html;
        root   /home/html/$user/domains/$host;
            proxy_pass   http://127.0.0.1:8080;
            proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Nginx常用的超时配置说明

1
client_header_timeout

语法 client_header_timeout time
默认值 60s
上下文 http server
说明 指定等待client发送一个请求头的超时时间(例如:GET / HTTP/1.1).仅当在一次read中,没有收到请求头,才会算成超时。如果在超时时间内,client没发送任何东西,nginx返回HTTP状态码408(“Request timed out”)

1
client_body_timeout

语法 client_body_timeout time
默认值 60s
上下文 http server location
说明 该指令设置请求体(request body)的读超时时间。仅当在一次readstep中,没有得到请求体,就会设为超时。超时后,nginx返回HTTP状态码408(“Request timed out”)

1
keepalive_timeout

语法 keepalive_timeout timeout [ header_timeout ]
默认值 75s
上下文 http server location
说明 第一个参数指定了与client的keep-alive连接超时时间。服务器将会在这个时间后关闭连接。可选的第二个参数指定了在响应头Keep-Alive: timeout=time中的time值。这个头能够让一些浏览器主动关闭连接,这样服务器就不必要去关闭连接了。没有这个参数,nginx不会发送Keep-Alive响应头(尽管并不是由这个头来决定连接是否“keep-alive”)
两个参数的值可并不相同
注意不同浏览器怎么处理“keep-alive”头
MSIE和Opera忽略掉”Keep-Alive: timeout=” header.
MSIE保持连接大约60-65秒,然后发送TCP RST
Opera永久保持长连接
Mozilla keeps the connection alive for N plus about 1-10 seconds.
Konqueror保持长连接N秒

1
lingering_timeout

语法 lingering_timeout time
默认值 5s
上下文 http server location
说明 lingering_close生效后,在关闭连接前,会检测是否有用户发送的数据到达服务器,如果超过lingering_timeout时间后还没有数据可读,就直接关闭连接;否则,必须在读取完连接缓冲区上的数据并丢弃掉后才会关闭连接。

1
resolver_timeout

语法 resolver_timeout time
默认值 30s
上下文 http server location
说明 该指令设置DNS解析超时时间

1
proxy_connect_timeout

语法 proxy_connect_timeout time
默认值 60s
上下文 http server location
说明 该指令设置与upstream server的连接超时时间,有必要记住,这个超时不能超过75秒。
这个不是等待后端返回页面的时间,那是由proxy_read_timeout声明的。如果你的upstream服务器起来了,但是hanging住了(例如,没有足够的线程处理请求,所以把你的请求放到请求池里稍后处理),那么这个声明是没有用的,由于与upstream服务器的连接已经建立了。

1
proxy_read_timeout

语法 proxy_read_timeout time
默认值 60s
上下文 http server location
说明 该指令设置与代理服务器的读超时时间。它决定了nginx会等待多长时间来获得请求的响应。这个时间不是获得整个response的时间,而是两次reading操作的时间。

1
proxy_send_timeout

语法 proxy_send_timeout time
默认值 60s
上下文 http server location
说明 这个指定设置了发送请求给upstream服务器的超时时间。超时设置不是为了整个发送期间,而是在两次write操作期间。如果超时后,upstream没有收到新的数据,nginx会关闭连接

1
proxy_upstream_fail_timeout(fail_timeout)

语法 server address [fail_timeout=30s]
默认值 10s
上下文 upstream
说明 Upstream模块下 server指令的参数,设置了某一个upstream后端失败了指定次数(max_fails)后,该后端不可操作的时间,默认为10秒

Debian修改ssh端口和禁止root远程登陆设置

linux修改端口22

1
vi /etc/ssh/sshd_config

找到#port 22
将前面的#去掉,然后修改端口 port 1234
重启服务就OK了

1
service sshd restart

1
/etc/init.d/ssh restart

为增强安全
先增加一个普通权限的用户,并设置密码

1
2
useradd test
passwd test

然后禁止ROOT远程SSH登录:

1
vi /etc/ssh/sshd_config

把其中的

1
PermitRootLogin yes

改为

1
PermitRootLogin no

重启sshd服务

1
service sshd restart

1
/etc/init.d/ssh restart

远程管理用普通用户test登录,然后用

1
su root

切换到root用户就可以拿到最高权限

国外VPS修改系统时间为北京时间

修改美国vps的系统时间为北京时间
也许大家在使用国外vps时感觉vps上的时间不是北京时间,感觉很别扭,今天我们就来改回为北京时间,首先登录你的vps,先用date命令查看下当前时间

1
date

Sun Aug 14 23:18:41 EDT 2011
现在我们就来改

1
2
rm -rf /etc/localtime  
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

再用date命令看下,你的vps的时间改变了吗?大部分linux vps的母鸡是允许每个vps修改时间的!看vpsma的时间已经修改好了。

1
date

Mon Aug 15 11:20:00 CST 2011
如果此时你的vps时间已经改成北京时间就不用看下面了,如果此时你的vps时间还没有修改好。再试下命令:

1
ntpdate stdtime.sinica.edu.tw

使用ntpdate stdtime.sinica.edu.tw 时候如果提示这个命令,先安装 ntpdate就可以了。
centos 系统的vps用命令:

1
yum -y install ntpdate ntp

Ubuntu系统的:

1
sudo apt-get install -y ntpdate ntp

安装完毕再试这个命令,如果还不可以的话,一般情况就是母鸡做了设置不让修改你vps的时间了。

手工创建casper-rw文件(用于liveusb保存文件)

casper-rw文件是用于我们在liveusb linux中保存我们对系统所做的更改,下面的方法用于手工创建casper-rw文件(我们甚至还能更改已创建casper-rw文件的大小)
1.创建新的casper-rw文件
打开终端,输入以下命令

1
dd if=/dev/zero of=casper-rw bs=1M count=1024

注: 把上面的count=1024改成你需要的大小
这样就在当前目录下生成了casper-rw文件,但这时候的casper-rw还不能用,你还需要格式化它在终端输入以下命令进行格式化

1
mkfs.ext3 casper-rw

OK,现在你可以把casper-rw文件拷到你的u盘投入应用了。

2.更改现有casper-rw文件的大小
打开终端,切换到casper-rw文件所在的目录,然后输入以下命令(最好先备份一下原文件)

1
dd if=/dev/zero bs=1M count=1024 >> casper-rw

注:把上面的count=1024改成你需要的大小
然后我们还需要check一下casper-rw文件,输入以下命令

1
e2fsck -f casper-rw

最后我们重新指定一下分区大小,输入以下命令

1
resize2fs casper-rw

如果以上的命令都正确执行了,那恭喜你,你已经得到一个新尺寸的casper-rw文件。

winscp使用sftp服务限制用户登录HOME目录

sftp和ftp是两种协议是不同的,sftp是ssh内含的协议,只要sshd服务器启动了,它就可用,它本身不需要ftp服务器启动。

1.查看openssh软件版本,想sftp服务用户只能访问特定的文件目录,版本需要4.8以上

1
2
3
4
rpm -qa | grep openssh
openssh-server-5.3p1-81.el6_3.x86_64
openssh-5.3p1-81.el6_3.x86_64
openssh-clients-5.3p1-81.el6_3.x86_64

2.新增用户,限制用户只能通过sftp访问

1
useradd -m -d /opt/ftp/dave -s /sbin/nologin dave

3.限制用户通过sftp登录进来时只能进入主目录,修改/etc/ssh/sshd_config文件

1
vim /etc/ssh/sshd_config
1
2
3
4
5
6
7
#Subsystem  sftp    /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
Match User dave
         ChrootDirectory /opt/ftp/dave
         X11Forwarding no
         AllowTcpForwarding no
         ForceCommand internal-sftp

重启ssh

目录权限设置上要遵循2点:
ChrootDirectory设置的目录权限及其所有的上级文件夹权限,属主和属组必须是root;
ChrootDirectory设置的目录权限及其所有的上级文件夹权限,只有属主能拥有写权限,权限最大设置只能是755。
如果不能遵循以上2点,即使是该目录仅属于某个用户,也可能会影响到所有的SFTP用户。

Debian或Ubuntu运行php5-fpm报错connect() to unix:/var/run/php5-fpm.sock

在ubuntu12.04中安装配置LNMP时 出现在php5-fpm的错误

1
2
3
4
5
6
7
8
2013/04/26 04:01:05 [crit] 6119#0:
 *4 connect() to unix:/var/run/php5-fpm.sock failed
(2: No such file or directory) while connecting to upstream,
client: 159.53.110.141,
server: 216.238.88.42,
request: "GET / HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:",
host: "216.238.88.42:9090

nginx中是这样配置的

1
2
3
4
5
6
7
8
9
10
11
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    # With php5-cgi alone:
    fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

我个人的配置是想用sock的方法 毕竟sock方式对于高并发来说 还是比使用cgi方式好的
问题其实出现在 fastcgi_pass得配置上面。在ubuntu 12.10安装了php5-fpm之后。我们可以去

1
/etc/php5/fpm/pool.d/www.conf

里面找到这样一段代码:

1
listen = 127.0.0.1:9000

在这上面代码的下面添加一行:

1
listen = /var/run/php5-fpm.sock

保存后启动php5-fpm

1
/etc/init.d/php5-fpm restart

这时就可以正常访问了

另外有可能是sock文件的执行权限有问题,对sock文件执行

1
chmod 777 php5-fpm.sock

再启动php5-fpm问题解决。