#raynix# When others see chance, I see cause.

6Apr/100

笔记: Nginx的转发

就像我启用了新的.info域名这样, 我会希望依旧在用旧的.cn域名访问的朋友在访问旧域名时浏览器会跳转到新域名. 另外如果你注册了很多域名指向同一个网站, 并且希望跳转到主域名, 那么Nginx的配置可以这样写:

server {
listen 80;
server_name old-domain1 old-domain2 old-domain3;
rewrite ^(.*)$ http://new-domain permanent;
}
UPDATE1:
操作符~表示大小写匹配, 而~*表示忽略大小写. !表示取反. 例如 ~ abc 匹配 abc, 而~* abc 匹配Abc ABC等.
括号里面的是参数, 例如
rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
:)
Tagged as: No Comments
23Dec/090

给Centos安装Nginx

10172022

Centos的缺省软件源里竟然没有Nginx,真让我感到意外了。还好,参考一下,办法还是现成的。

Red Hat Enterprise Linux / CentOS Linux Enable EPEL (Extra Packages for Enterprise Linux) Repository

还是做个笔记吧:

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

之后就可以yum install nginx啦。 :)

Tagged as: , No Comments
30Nov/090

用Nginx给Joomla!提速

Joomla!是个不错的基于PHP的CMS,在LAMP环境下安装运行都非常方便,不过性能并非最优。一个提速的方法是用Nginx服务静态内容。

Nginx的配置片段:

upstream apache1{
server 127.0.0.1:8001;
}

server{
listen 80;
server_name mysite.com.cn www.mysite.com.cn;

location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
root   /home/raymond/public_html/www.mysite.com.cn;
expires 14d;

gzip on;
gzip_comp_level 3;
gzip_types text/plain text/javascript text/html text/css image/png application/json application/x-javascript text/xml application/xml+rss;
gzip_vary on;
gzip_buffers 16 8k;
}

location / {
proxy_pass    http://apache1;
proxy_set_header   Host             $http_host;
proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

}

}

apache2的配置片段

<VirtualHost 127.0.0.1:8001>
ServerName www.mysite.com.cn
DocumentRoot /home/raymond/public_html/www.mysite.com.cn
</VirtualHost>

记得把apache2主配置文件中的Listen 80 改为Listen 8001。如果有多个虚拟主机,还要加上Listen 8002……