最近兩個星期,轉了兩臺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
|
新聞熱點
疑難解答