Tengine 的编译安装
1 选定目录以及解压文件
cd /optwget http://tengine.taobao.org/download/tengine-2.3.3.tar.gz
2 编译安装
cd tengine-2.3.3./configure --prefix=/opt/tengine233make && make install
配置文件的讲解
content
cd tengin233lsconf html logs sbinconf --- 存放配置文件html --- 存放网页的静态文件目录logs --- 日志sbin --- 存放可执行命令
environment variable—quick start
Nginx/opt/tengine233/sbinsystem/opt/python396/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/binPATH="/opt/tengine233/sbin:/opt/python396/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin"vim /etc/profile
start nginx
/opt/tengine233/sbin/nginx# after add environment variablenginx
check port occupied
netstat -tunlp | grep 80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13902/nginx: masterlsof -i :80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEnginx 13902 root 6u IPv4 132914 0t0 TCP *:http (LISTEN)nginx 13903 nobody 6u IPv4 132914 0t0 TCP *:http (LISTEN)
usual command
nginx # 首次输入是直接启动,不得再次输入nginx -s reload # 平滑重启,重新读取nginx的配置文件,而不重启进程nginx -s stop # 停止nginx进程nginx -t # 检查配置文件 相当于 pytho
nginx -tnginx: the configuration file /opt/tengine233/conf/nginx.conf syntax is oknginx: configuration file /opt/tengine233/conf/nginx.conf test is successful
默认首页
http://218.78.112.182:10001/index.html
Nginx配置文件的学习
简介
1. 代码风格C语言,分号结束,表示每一行的的配置;2. 代码块1. http {} # 定义多个代码,是Nginx核心功能配置点2. server {} # 虚拟主机代码,定义了网站的目录地址,以及首页文件名字,监听端口等功能3. localtion {} # 域名匹配代码块
功能代码结构
http {server{listen 80;servername www.whereabouts.com;location / {}}}
默认配置文件备份
配置文件内有两份全站配置
http,但是第二份完全被注释,因此修改第一份http即可
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#error_log "pipe:rollback logs/error_log interval=1d baknum=7 maxsize=2G";#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;#access_log "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G" main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;location / {root html;index index.html index.htm;}#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;#}# pass the Dubbo rpc to Dubbo provider server listening on 127.0.0.1:20880##location /dubbo {# dubbo_pass_all_headers on;# dubbo_pass_set args $args;# dubbo_pass_set uri $uri;# dubbo_pass_set method $request_method;## dubbo_pass org.apache.dubbo.samples.tengine.DemoService 0.0.0 tengineDubbo dubbo_backend;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# upstream for Dubbo rpc to Dubbo provider server listening on 127.0.0.1:20880##upstream dubbo_backend {# multi 1;# server 127.0.0.1:20880;#}# 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;# }#}}
nginx 的 web站点
首页静态文件的存放路径
/opt/tengine233/html
默认主页源码保存
<!DOCTYPE html><html><head><title>Welcome to tengine!</title><style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}</style></head><body><h1>Welcome to tengine!</h1><p>If you see this page, the tengine web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and support please refer to<a href="http://tengine.taobao.org/">tengine.taobao.org</a>.</p><p><em>Thank you for using tengine.</em></p></body></html>
自定义个人主页以及图片存储路径
# 存放路径[root@vvkt7whznuckhiz2-0723575 html]# ls50x.html index.html smooth.jpg[root@vvkt7whznuckhiz2-0723575 html]# pwd/opt/tengine233/html[root@vvkt7whznuckhiz2-0723575 html]# vim index.html<!DOCTYPE html><body><h4>Thinking less , practice more!<h4><img src="./smooth.jpg"></body>
虚拟主机

第二个 server
完整配置文件
worker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;gzip on;server {listen 10001;server_name localhost;charset utf-8;location / {root /s25linux/;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}server {listen 40001;server_name localhost;charset utf-8;location / {root /s25python/;index index.html index.htm;}}}
外部配置文件写入
echo "I love you, you love me, mixue ice city lovely" > /s25nginx/index.html
最终效果

创建显示网页
echo "I love you, you love me, mixue icecream honey and tea" > /s25linux/index.htmlecho "You watch my eyes, listen to me,not afraid of wind and rain." > /s25python/index.html
最终显示效果

404 页面设计
配置文件的修改
server {listen 10001;server_name localhost;charset utf-8;# 添加此行代码,当用户请求出错时,出现404的时候,会返回特定的页面,在root定义的根目录下寻找40x.html文件#error_page 404 /40x.html;#access_log logs/host.access.log main;#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;location / {root /s25linux/;index index.html index.htm;}}
预备修改的资源文件 40x.html
cd /s25linuxtouch 40x.htmlvim 40x.html
H5 资源文件
<!DOCTYPE html><html lang="en" ><head><meta charset="UTF-8"><title>404</title></head><body><h4>"What you see is what you get, but this page is not exist."</h4></body></html>
检查并且软重启 Nginx
nginx -s reload# 或者关闭并启动nginx -s stopnginx
最终效果

Nginx 访客日志
定义及用途
1. 特点:能够记录,分析用户的请求行为什么时间点访问最频繁,网站流量峰值记录用户的请求频率,依次检测是否为爬虫等恶意请求,进行封禁;检测躲在用户代理后的真实IP检测用户IP,请求时间,请求URL内容;2. 格式log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';3. 对变量的解释
反向代理
正向代理相当于业务代办,面向用户,也就是服务需求方
反向代理相当于中介,面向房东,也就是服务提供方
负载均衡
为什么做负载均衡?[静态资源加速 & 流量平衡]
1. 代理服务器负载均衡 使用代理服务器,可以将请求转发给内部的服务器,使用这种加速模式显然可以提升静态网页的访问速度。2. 使用代理服务器将请求均匀转发给多台服务器,从而达到负载均衡的目的。
实操
实现逻辑

1 修改 nginx.conf配置,构建代理池
upstream s25real_server {server 192.168.1.9:5555;server 192.168.1.9:6666;}
第一个主机10001端口用作网关,交给代理池
server {listen 10001;server_name localhost;charset utf-8;location / {proxy_pass http://s25real_server;}}
第二个server 5555端口负责提供数据
server {listen 5555;server_name localhost;charset utf-8;location / {root /s25python/;index index.html index.htm;}}
第三个server 6666依然是为了提供资源
server {listen 5555;server_name localhost;charset utf-8;location / {root /s25linux/;index index.html index.htm;}}
2 完整配置文件
worker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;gzip on;upstream s25real_server {server 192.168.1.9:5555;server 192.168.1.9:6666;}server {listen 10001;server_name localhost;charset utf-8;location / {proxy_pass http://s25real_server;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}server {listen 5555;server_name localhost;charset utf-8;location / {root /s25python/;index index.html index.htm;}}server {listen 6666;server_name localhost;charset utf-8;location / {root /s25linux/;index index.html index.htm;}}}
集群
概念
特点
1, 高性能;
2,价格有效性;
采用计算机集群比采用同等运算性能的大型计算机更具有性价比3, 可伸缩性;
硬件的扩展性强,且不影响面向服务的连续性;4, 透明性;
负载均衡算法
- 默认轮询机制,每一台服务器处理一次访问请求;
- 加权轮询,给代理池的每一个主机分配权重,比如 weight=4; weight=1;
upstream s25real_server {
server 192.168.1.9:5555 weight=4;
server 192.168.1.9:6666 weight=1;
}
报错及处理
nginx: [error] invalid PID number ““ in “**/nginx/logs/nginx.pid
解决方法 :进入到nginx的安装目录位置,进入sbin下执行 nginx -t 检查配置是否正确看到 successful 说明配置没问题,如果不是,好好检查nginx.conf之后执行以下两条命令:./nginx -c /opt/tengine233/conf/nginx.conf./nginx -s reload修后使用以下命令,查看nginx进程:ps -ef|grep nginx原文链接:https://blog.csdn.net/qq_36949163/article/details/119874257
https://www.cnblogs.com/pyyu/p/10009493.htmlhttps://blog.csdn.net/lmiao1992/article/details/97516293?utm_term=yum%E9%95%9C%E5%83%8F%E6%B2%A1%E6%9C%89redis&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-1-97516293&spm=3001.4430

