用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……

Leave a Reply

Your email address will not be published. Required fields are marked *