nginx简配new

上传人:xins****2008 文档编号:103257250 上传时间:2019-10-06 格式:DOC 页数:5 大小:28.50KB
返回 下载 相关 举报
nginx简配new_第1页
第1页 / 共5页
nginx简配new_第2页
第2页 / 共5页
nginx简配new_第3页
第3页 / 共5页
nginx简配new_第4页
第4页 / 共5页
nginx简配new_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《nginx简配new》由会员分享,可在线阅读,更多相关《nginx简配new(5页珍藏版)》请在金锄头文库上搜索。

1、Nginx (engine x) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP代理服务器。Nginx的优点:1、高并发连接:官方测试能够支撑5万并发连接,在实际生产环境中跑到23万并发连接数。2、内存消耗少:在3万并发连接下,开启的10个Nginx进程才消耗150M内存。3、配置文件简单:风格和程序一样通俗易懂。4、成本低廉:Nginx为开源软件,开始免费使用。5、支持Rewrite重写规则:能够根据域名、URL的不同,将HTTP请求分到不同的后端服务器群组。6、那只的健康检查功能:如果Nginx Proxy后端的某台Web服务器宕机了,不会影响前端访问。

2、7、节省带宽:支持GZIP压缩,可以添加浏览器本地缓存的Header头。8、稳定性高:用于反向代理,宕机的概率微乎其微。Nginx的主要应用类别1、使用Nginx 结合FastCGI 运行 PHP 、 JSP 、 Perl 等程序。2、使用Nginx 作反向代理、负载均衡、规则过滤。3、使用Nginx 运行静态HTML页面、图片。4、Nginx 与其他新技术的结合应用。Nginx如何实现高并发: I/O模型采用异步非阻塞的事件驱动机制,由进程循环处理多个准备好的事件,如epoll机制;Nginx与Apache对高并发处理上的区别: 对于Apache,每个请求都会独占一个工作线程,当并发量增大时

3、,也会产生大量的工作线程,导致内存占用急剧上升,同时线程的上下文切换也会导致CPU开销增大,导致在高并发场景下性能下降严重; 对于Nginx,一个worker进程只有一个主线程,通过事件驱动机制,实现循环处理多个准备好的事件,从而实现轻量级和高并发;部署配置1. 所需包yum install gcc gcc-c+ make cmake ncurses ncurses-devel libxml2 libxml2-devel openssl-devel bison bison-devel libevent pcre*2. 切换到nginx的根目录下 运行 ./configure3. 运行 make

4、4. 运行 make installnginx 默认目录位于 /usr/local/nginx安装 nginx 、pcrerootlocalhost pack#tar zxf pcre-8.30.tar.gzrootlocalhost pack#cd pcre-8.30rootlocalhost pcre-8.30#./configure -prefix=/usr/local/pcre ; make ; make installrootlocalhost pack#groupadd nginxrootlocalhost pack#useradd -r -s /sbin/nologin -g n

5、ginx nginxrootlocalhost pack#tar zxf nginx-1.3.12.tar.gzrootlocalhost pack#cd nginx-1.3.12rootlocalhost nginx-1.3.12#./configure -user=nginx -group=nginx -prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_module -with-http_flv_module -with-http_gzip_static_module -with-google_perf

6、tools_module -sbin-path=/usr/local/nginx/sbin/nginx -conf-path=/usr/local/nginx/conf/nginx.conf -pid-path=/usr/local/nginx/nginx.pid -with-pcre=/usr/local/src/pack/pcre-8.30(源码路径)rootlocalhost nginx-1.3.12#make ; make installrootlocalhost local#grep -v # nginx/conf/nginx.conf | grep -v $user nginx n

7、ginx; # 设定运行用户、组worker_processes 1;error_log /usr/local/nginx/logs/nginx_error.log crit;# 错误日志路径google_perftools_profiles /var/tmp/tcmalloc;# 使用 TCMalloc 优化 nginxworker_rlimit_nofile 65535;events worker_connections 65535;http # 利用反向代理功能提供负载均衡支持 include mime.types; default_type application/octet-stre

8、am; server_names_hash_bucket_size 128; # 设定请求缓存 client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 300m;# 设置客户端上传文件大小限制 sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; server_tokens off; client_body_buffer_size 512k; proxy_connect_timeout 5; prox

9、y_send_timeout 60; proxy_read_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; gzip on;# gzip 网页压缩 gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript tex

10、t/css application/xml; gzip_vary on; server # 禁止IP访问站点 server_name _; return 404; server listen 80; server_; index index.html index.htm index.jsp index.do;# 默认访问首页地址 root /data/abc/; # 网站资源根路径 if (-d $request_filename) rewrite /(.*)(/)$host/$1$2/permanent; location .(jsp|jspx|do)?$ # 设定 jsp 页面教由 res

11、in 处理 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_passhttp:/127.0.0.1:8080;# 请求转向 resin location .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ # 设定静态文件直接读取 expires 3

12、0d; location .*.(js|css)?$ expires 1h; error_page 500 502 503 504 /50x.html; location = /50x.html root html; rootlocalhost local#/usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号