nginx-1:安装配置nginx

Nginx:
Nginx本身是一款静态WWW软件(html,js,css,jpg)
静态小文件高并发,同时占用的资源少。基于异步IO模型epoll

特点:
1、www web服务
http 80
2、负载均衡(反向反向代理proxy)
3、web cache(web缓存)

优点:
0、配置更简单,更灵活
1、高并发(静态小文件并发1-2W)
2、占用资源少(2W并发 开10个线程服务 内存消耗几百M)
3、功能种类比较多(web,cache,proxy),每一个功能都不是特别强
4、支持epoll模型。(让Nginx可以支持高并发)
5、nginx配合动态服务和apache有区别。
6、利用nginx可以对Ip限速,可以限制连接数。

LAMP:
静态→apache
动态→php(libphp5.so)是apache配置文件当中的一个模块
博客文章→php去请求mysql

LNMP
镜像→Nginx
动态→PHP FCGI(服务器) 9000端口 (fastcggi_pass http:ip:9000)
博客文章→php去请求mysql

Nginx应用场合
1、静态服务(图片、视频)并1-3W
2、动态服务 nginx+fastcgi方式运行php,jsp。并发:500-1500
3、反向代理,负载均衡。日PV2000W以下,都可以直接用Nginx做代理。

Nginx、Apache、lighttpd对比
小文件:处理小文件小于1M,nginx和lighttpd比apache更有优势,lighttpd更强
动态:三者差别不大,apache又有优势一点。php、JAVA、数据库 300-1000

建议:对外的业务nginx(源码编译安装),对内的业务apache(yum httpd mysql-server php)

nginx虚拟主机:
1、基于域名:外部网站
2、基于端口:公司内部网站,外部网站后台
3、基于IP(不怎么用)

安装nginx
安装pcre支持http重写,如果是编译安装pcer的话,在编译nginx的时候需要加上--with-pcre=/applicatione/pcre
yum install pcre pcre-devel -y
安装openssl支持https
yum install openssl openssl-devel -y
cd /usr/local/share
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
useradd nginx -s /sbin/nologin -M
./configure --user=nginx --group=nginx --prefix=/application/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
启动
/application/nginx/sbin/nginx
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx -s stop
/application/nginx/sbin/nginx -s reload


Nginx 基本配置

1、Nginx core modules(Main、Events)
2、其他模块(Gaccess、fastcgi、gzip压缩模块、log、proxy、rewrite、upstream)

配置文件
nginx.conf

worker_processes 1; (跟cpu核数相同)
events{
work_connections 1024; 处理的总连接数

}

server {
listen 80;
server_name www.lmkmike.com;
root html;
index index.html;
}
server {
listen 80;
server_name bbs.lmkmike.com;
root html/bbs;
index index.html;
}
server {
listen 80;
server_name blog.lmkmike.com;
root html/blog;
index index.html;

一个server就是一个虚拟主机
可以多个server都配置80端口,但是server_name是不同的域名,比如www.lmkmike.com、bbs.lmkmike.com

状态模块,查看nginx信息
server {
listen 80;
server_name blog.lmkmike.com;
stub_status on;
access_log off;
}

查看网页blog.lmkmike.com
Active connections: 1
server accepts handled requests
16 16 111
Reading: 0 Writing: 1 Waiting: 0

转载于:https://blog.51cto.com/13491150/2058667

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值