您的位置:首页 > 运维架构 > Nginx

Centos yum 安装nginx+php+mysql

2013-06-28 17:02 459 查看
yum-yinstallyum-fastestmirror

yum-yupdate

yum-yinstallpatchmakegccgcc-c++gcc-g77flexbison

yum-yinstalllibtoollibtool-libskernel-develautoconf

yum-yinstalllibjpeglibjpeg-devellibpnglibpng-devel

yum-yinstallfreetypefreetype-devellibxml2libxml2-develzlibzlib-devel

yum-yinstallglib2glib2-develbzip2diff*

yum-yinstallbzip2-develncursesncurses-develcurlcurl-devele2fsprogs

yum-yinstalle2fsprogs-develkrb5krb5-devellibidnlibidn-devel

yum-yinstallopensslopenssl-develvim-minimal


64位替换i386为x86_64

yum-yinstallmysqlmysql-servermysql-devel

yum-yinstallphpphp-mysqlphp-cgiphp-mbstringphp-gdphp-fastcgiphp-pearphp-pear-DBphp-fpmphp-cliphp-pdophp-mcryptphp-tidyphp-xmlphp-xmlrpcphp-pecl-memcachephp-eaccelerator

yum-yinstallnginx(如果无法安装,执行rpm-Uvhftp://ftp.univie.ac.at/systems/linux/fedora/epel/beta/6/i386/epel-release-6-5.noarch.rpm)
所有的配置文件都在/etc目录

chkconfigmysqldon

chkconfigphp-fpmon

chkconfignginxon

servicemysqldstart

mysqladmin-urootpassword123456

创建www用户和组,以及主机需要的目录,日志目录



groupaddwww

useradd-gwwwwww

mkdir-p/home/www

chmod+w/home/www

mkdir-p/home/www/logs

chmod777/home/www/logs

chown-Rwww:www/home/www

第一个www为文件拥有者名称,第二个www为所属群组。

vi/etc/nginx/nginx.conf



userwwwwww;




worker_processes2;#这里根据你的CPU和内存配置,设置2到10都OK


error_log/home/www/logs/nginx_error.logcrit;



pid/usr/local/nginx/logs/nginx.pid;

#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.

worker_rlimit_nofile51200;

events{

useepoll;

worker_connections51200;

}

http{

includemime.types;

default_typeapplication/octet-stream;

#charsegb2312;#默认编码,可以不设置

server_names_hash_bucket_size128;

client_header_buffer_size16k;

large_client_header_buffers416k;

client_max_body_size8m;

sendfileon;

tcp_nopushon;

keepalive_timeout60;

tcp_nodelayon;

fastcgi_connect_timeout300;

fastcgi_send_timeout300;

fastcgi_read_timeout300;

fastcgi_buffer_size64k;

fastcgi_buffers464k;

fastcgi_busy_buffers_size128k;

fastcgi_temp_file_write_size128k;

gzipon;

gzip_min_length1k;

gzip_buffers416k;

gzip_http_version1.0;

gzip_comp_level5;

gzip_typestext/plaintext/javascriptapplication/x-javascripttext/cssapplication/xml;

gzip_varyon;

#limit_zonecrawler$binary_remote_addr10m;

server{

listen80;

server_namelocalhost;

root/home/www;

location/status{

stub_statuson;

access_logoff;

}

location/{

#这里是把所有不存在的文件和目录,全都转到index.php处理

try_files$uri$uri//index.php?q=$uri&$args;

}

#这里分开放到server.conf是为了再开server的时候方便,统一调用,放到/etc/nginx/目录下

includeserver.conf;

log_formataccess'$remote_addr-$remote_user[$time_local]"$request"'

'$status$body_bytes_sent"$http_referer"'

'"$http_user_agent"$http_x_forwarded_for';

access_log/home/www/logs/access.logaccess;

}



/etc/nginx/conf.d/default.conf




server{

listen80;

server_nameyourdomain.com;

root/home/www/yourdomain;

if($host!~*yourdomain\.com$){

return444;

}

location/{

try_files$uri$uri//index.php?q=$uri&$args;

}

includeserver.conf;#这里复用了,这段就省了

access_log/home/www/logs/yourdomain.com_access.logaccess;

}

}



vi/etc/nginx/server.conf



indexindex.htmlindex.htmindex.php;




#limit_conncrawler20;


location~/\.ht{

denyall;

}



location~.*\.(sqlite|sq3)${

denyall;

}

location~.*\.php${

fastcgi_passunix:/tmp/php-cgi.sock;

#fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

includefcgi.conf;

}

location~.*\.(gif|jpg|jpeg|png|bmp|swf|ico)${

expires30d;

access_logoff;

}




location~.*\.(js|css)?${

expires30d;

access_logoff;

}

/sbin/iptables-IINPUT-ptcp--dport80-jACCEPT

开放80端口

servicephp-fpmstart

servicenginxstart

OK!

nginx测试

/usr/local/nginx/sbin/nginx-t

nginx平滑重启命令

/usr/local/nginx/sbin/nginx-sreload
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: