nginx--安装与配置
nginx的特点
1、web和反向代理服务器,相对apache支持更多的并发,占用资源少,效率高。
2、可以作为反向代理服务器、代理服务器(不及haproxy)
3、邮件代理服务器、缓存服务器(加cache插件实现web缓存功能)
4、支持1-2W的并发量甚至更多
5、在3W并发下,10个进程消耗200M的内存
6、可以作为负载均衡的功能
7、nginx使用的是epoll和kqueue模型
选择web服务器
1、静态业务:采用nginx
2、动态业务:采用nginx和apache均可
并发不大的情况下可以采用apache
(一)、软件准备
1.pcre wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz 2.nginx wget http://nginx.org/download/nginx-1.6.2.tar.gz
(二)、安装
1、安装pcre tar xf pcre-8.35.tar.gz cd pcre-8.35 ./configure make make install 2、安装nginx useradd nginx -s /sbin/nologin tar xf nginx-1.6.2.tar.gz cd nginx-1.6.2 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/bao/pcre-8.36 make make install
(三)、配置
1、添加用户:user nginx nginx
2、worker_processes 1; 进程数可根据CPU的数量来定
3、添加事件
events {
use epoll ##添加的事件
worker_connections 1024;
}
4、增加虚拟主机
方法一、
在nginx.conf里添加server
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
#侦听80端口
listen 80;
#定义使用www.xx.com访问
server_name www.xx.com;
#设定本虚拟主机的访问日志
access_log logs/www.xx.com.access.log main;
#默认请求
location / {
root /root; #定义服务器的默认网站根目录位置
index index.php index.html index.htm; #定义首页索引文件的名称
fastcgi_pass www.xx.com;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# 定义错误提示页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /root;
}
方法二、(此方法便于管理,优化配置文件) 把nginx.conf里的server删掉 在conf里mkdir/extra 把server内容写到nginx_vhost.conf里 在nginx.conf的http里添加:include extra/nginx_vhost.conf
浙公网安备 33010602011771号