nginx学习笔记
来源:互联网 发布:正规淘宝客服兼职平台 编辑:程序博客网 时间:2024/06/16 07:29
nginx定义:http服务器,反向代理服务器,邮件服务器。
常用功能:http代理,反向代理;负载均衡;Web缓存。
编辑安装命令:
- ./configure
- make
- sudo make install
查看进程:ps -ef | grep nginx
停止:./nginx -g TERM | INT | QUIT
重启:/usr/local/nginx/sbin/nginx -s reload 或者sudo kill -HUP 6394
检查:sudo /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
模块化结构:
核心模块
标准http模块
可选http模块
邮件服务模块
第三方模块
请求处理机制:异步非阻塞和多进程机制
事件驱动机制:select库,poll库,epoll库,rtsig模型等
nginx服务器进程:
主进程
工作进程
缓存索引重建及管理进程
nginx后端服务器组的配置指令
- upstream
- server
- ip_hash
- keepalive
- least_conn
负载均衡配置:
8081和8080对应两个不同端口号的tomcat
upstream demo_site { server 127.0.0.1:8081 weight=1; server 127.0.0.1:8080 weight=1; }location /demo { proxy_pass http://demo_site;}
使用proxy_cache 进行静态资源的缓存。
经过测试,第一次请求静态资源会经过web应用,之后请求由nginx直接返回。
nginx.conf示例:
#user nobody;worker_processes 1;error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /var/tmp/temp_nginx; proxy_cache_path /var/cache/nginx/ levels=1:2 keys_zone=nginx_cache:100m inactive=1d max_size=10g; upstream demo_site { server 127.0.0.1:8081 weight=1; server 127.0.0.1:8080 weight=1; } server { listen 80; server_name localhost; #charset koi8-r; access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location ~* ^.+\.(js|ico|gif|jpg|jpeg|png|html|htm)$ { access_log logs/access.log; proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_cache nginx_cache; proxy_cache_valid 200 302 12h; proxy_cache_key $host$uri$is_args%args; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://demo_site; expires 1d; } location /demo { proxy_pass http://demo_site; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
0 0
- nginx学习笔记
- Nginx学习笔记
- Nginx学习笔记
- nginx学习笔记0
- nginx学习笔记1
- nginx学习笔记2
- nginx学习笔记
- nginx学习笔记
- nginx rewrite学习笔记
- nginx学习笔记【安装】
- nginx学习笔记1
- nginx学习笔记2
- Nginx学习笔记 第一章
- nginx学习笔记
- nginx 新手学习笔记
- Nginx学习笔记1
- nginx的学习笔记
- nginx 源代码学习笔记
- zcmu 1616: 最长回文串
- Glusterfs的常用命令
- Zynq的LWIP裸奔应用
- 策略模式、代理模式
- jsp内置对象总结
- nginx学习笔记
- 独立按键和矩阵键盘
- Java: Annotation 浅析(二) 自定义注解处理器
- JZOJ8.13最大值
- 八皇后问题优化版:DFS剪剪剪
- poj 1416 Shredding Company (应该是用dfs吧,但是想了一下午不知道怎么递归来做,所以暴力做了)
- 基础篇-Service解析
- 用窗口程序做Java socket编写聊天程序
- 字符矩阵中是否存在环