首页 > 开发 > Nginx > 正文

centos上apache2转nginx手记

2018-10-16 21:24:56
字体:
来源:转载
供稿:网友

最近两个星期,转了两台debian5和两台centos的apache服务器到nginx ,
nginx确实性能优越,最明显的感受就是系统负载降低不少。

系统 Centos 5.0+ x86_64 ,先前使用apache

启用 EPEL repo
i386
#rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
x86_64
#rpm -ihv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm

 
一键安装
# yum install nginx php-fpm php-cgi

 
停止和禁用apache
#service httpd stop
#chkconfig –levels 2345 off

 
启动Nginx与PHP-Fpm

#/etc/init.d/nginx restart
#/etc/init.d/php-fpm restart

 
编辑nginx配置文件:
#vi /etc/nginx/nginx.conf
修改ngxin运行用户为原apache运行用户:apache,这样可以不用修改web目录权限的情况下完美解决权限问题。

添加虚拟主机:
server
{
listen 80;
server_name 80ht.cn 80ht.cn;
rewrite ^(.*) http://www.80ht.cn permanent; nginx实现301重定向
index index.php index.html;
root /var/www/blog/;
location ~ .*/.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*/.(js|css)?$
{
expires 12h;
}
access_log off;
}

#vi /etc/php-fpm.conf
修改ngxin运行用户为原apache运行用户:apache

常见问题:
nginx配置httpd服务遇到问题:No input file specified 的解决
设置fastcgi
#vi /etc/nginx/fastcgi_params
添加:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

php-fpm 和 nginx 参数调优可参考
http://hulei.info/2010/04/27/nginxphp-fpm_tunning/
具体的配置还需根据实际生产环境和应用调整。

Nginx开启服务状态页面:
#vi /etc/nginx/nginx.conf
server
{
listen 80;
server_name stat.80ht.cn;
location / { #主要是这里代表根目录显示信息
stub_status on;
access_log off;
}
}


转载请注明出处:http://www.80ht.cn/?p=1453

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表