nginx简介web服务
1 HTTP基础 www.nginx.org www.nginx.net 80端口 443加密端口 ODI 第七层应用层 常用 nginx apache(静态的WEB软件) 2 经典组合 LNMP linux nginx mysql php LAMP linux apache mysql php 3 nginx 简介 俄罗斯人开发的开源的高并发的静态WEB服务器软件 代码700多K C语言开发适合 linux unix windows平台, 特点:高并发,占用资源少,静态小文件(1M),配置简单,灵活轻量,网络IO模型epoll,配合动态服务用fastcgi,支持虚拟主机 功能:1web服务 2可做方向代理(负载均衡)3 cache(web)缓存=squid(缓存软件) 淘宝把nginx更改成tengine 4 网站的并发 nginx 1-3W 开10个线程 php 500-1000 mysql 300-1000 5 nginx 应用场景 5.1 静态服务 (图片 视频)HTML js,css,flv jpg gif 国内静态服务器常用nginx lighttpd 并发1-3w 5.2 动态服务 nginx + fastcgi的方式运行PHP JSP 并发 300-1000 5.3 反向代理 负载均衡 (PV2000W以下,并发1W以下,就可用)haproxy f5 a10 5.4 缓存服务 类似 squid varnish 6 select 和 epoll 模型 7 nginx支持虚拟主机 一个server标签端就是一个虚拟主机 7.1 基于域名的虚拟主机 ***** 外部网站 7.2 基于端口的虚拟主机 *** 网站的后台 7.3 基于IP的虚拟主机 (不用) 8 nginx 安装 #建议换一下YUM源 yum -y install wget wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 8.1 安装依赖: ( 因为nginx 的rewrite模块 伪静态URL改写用到它的库openssl加密 pcre兼容正则) yum -y install pcre pcre-devel openssl-devel openssl 8.2 编译安装 useradd nginx -s /sbin/nologin -M 创建虚拟用户 下载 wget http://nginx.org/download/nginx-1.6.3.tar.gz tar xf nginx-1.6.3.tar.gz cd nginx-1.6.3 ./configure --help 查看选项 ./configure \ --prefix=/app/nginx-1.6.3 \ #编译更改默认用户为nginx --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_stub_status_module make && make install cd /app; ln -s nginx-1.6.3/ nginx /app/nginx/sbin/nginx ss -tunlp|grep 80 测试 /app/nginx/sbin/nginx -V 查看编译安装的参数 9 nginx 模块 要要注意的是 nginx的模块是被比那一进nginx的,属于静态编译方式 如果想添加新的模块功能,需要重新编译! apache属于动态动态编译,添加模块可以通过apxs编译目标模块的方式添加 除了标准的核心模块之外还有以下重要模块 *ngx_http_core_module 包括一些核心HTTP参数配置,对应NGINX的配置为HTTP区块部分 *ngx_http_access_module 访问控制模块,用来控制网站用户对其的访问 *ngx_http_gzip_module 压缩模块,对其放回到额数据压缩(属于性能优化) *ngx_http_fastcgi_module fastcgi模块,和动态应用相关,如PHP *ngx_http_proxy_module 代理模块 *ngx_http_upstream_module 负载均衡模块,可以实现网站的负载均衡工程及其节点的健康检查 *ngx_http_rewrite_module URL地址重写模块(伪装动态URL成静态URL,便于搜索引擎收录) ngx_http_limit_conn_module 限制用户并发连接和请求书的模块 ngx_http_limit_req_module 限制请求的速率的模块 *ngx_http_log_module 访问日志模块,以指定格式记录客户的访问日志等信息 ngx_http_auth_basic_module WEB认证模块,设置WEB用户通过账号密码访问NGINX ngx_http_ssl_module SSL模块,用于加密的HTTP连接,如https ngx_http_core_module 记录nginx基本访问状态信息等的模块 10 主配置文件 nginx.conf 主配置文件 (基于域名的虚拟主机 多用 基于端口和IP了解即可) --------------------------------------------- worker_processes 1; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.tao.org; root html/www; location / { index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } --------------------------------------------- mkdir ../html/blog -p 创建目录 echo "blog.tao.org" >../html/blog/index.html 创建主页文件 /app/nginx/sbin/nginx -t 检查语法(很重要) nginx: the configuration file /app/nginx-1.6.3/conf/nginx.conf syntax is ok nginx: configuration file /app/nginx-1.6.3/conf/nginx.conf test is successful /app/nginx/sbin/nginx -s reload 重新加载配置(不用重启,不影响用户体验)
本文来自博客园,站在巨人的肩膀上,坚持开源精神,遵循开源协议:Apache Licene 2.0协议。
浙公网安备 33010602011771号