标签归档:nginx

nginx防止空主机头域名指向

空主机头域名指向是指,比如我有个www.aaa.com的站点,别人用www.bbb.com域名指向了aaa.com的IP,这样访问www.bbb.com也能显示aaa.com的内容了。
在nginx的配置文件中已经定义了空主机头返回404页面。

vim /etc/nginx/nginx.conf

如下:

server {
        limit_conn addr 10;
        listen       80;
        server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        error_page  404              /404.html;

        location = /404.html {
            root   /usr/share/nginx/html;
        }

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


只要将定义网站的server段放在它的后面就能实现空主机头的域名都返回404页面。
继续阅读nginx防止空主机头域名指向

php添加XCache脚本加速

XCache是一个php的脚本加速器(opcode缓存器/优化器),功能和eAccelerator差不多。系统为CentOS6.3,环境为nginx+php-fpm。

官网:http://xcache.lighttpd.net/

1、下载安装XCache

cd /tmp
wget http://xcache.lighttpd.net/pub/Releases/3.0.0/xcache-3.0.0.tar.gz
tar -zxvf xcache-3.0.0.tar.gz
cd xcache-3.0.0
/usr/bin/phpize
./configure --with-php-config=/usr/bin/php-config --enable-xcache --enable-xcache-optimizer
make
make install

安装完后,会自动在/usr/lib/php/modules/目录内添加xcache.so模块。

选项说明:
–enable-xcache:包含XCache支持。
–enable-xcache-optimizer:启用操作码优化。

注:XCache3.0.0开始使用 extension= 来加载XCache。不再支持采用 zend_extension= 方式加载。
继续阅读php添加XCache脚本加速

nginx下discuz! x2.5伪静态设置

管理员登录到后台,选择“全局-SEO设置-URL静态化”,可以看到有“页面 标记 格式 可用”几个标题,将可用下面的方框里都选中,Rewrite兼容性选否,点击提交。
找到nginx配置文件中配置这个bbs域名的server段,在location /内添加伪静态规则。
比如原来是:

...
server {
    listen       80;
    server_name  www.aaa.com;
    access_log  /var/log/nginx/aaa.com.log  main;
    location / {
        root   /home/webroot;
        index  index.html index.htm index.php;
    }
}
...


修改后为:

...
server {
    listen       80;
    server_name  www.aaa.com;
    access_log  /var/log/nginx/aaa.com.log  main;
    location / {
        root   /home/webroot;
        index  index.html index.htm index.php;
        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;
        }
    }
}
...

nginx设置虚拟目录

nginx建立虚拟目录的配置文件放在/etc/nginx/conf.d目录下。系统用的是CentOS6.3。

首先在nginx.conf中查找有没有:

include /etc/nginx/conf.d/*.conf

这一句,没有的话要加在http块内。

添加虚拟目录
比如要放两个虚拟目录:
blog.aaa.com在/home/blog.aaa目录
bbs.bbb.com在/home/bbs.bbb目录

我们把这两个虚拟目录写在一个配置文件里。

cd /etc/nginx/conf.d
vim virtualhost.conf

添加: 继续阅读nginx设置虚拟目录