自己如何做网站关键词排名,拓者吧装修效果图,微网站趋势,做网站湖州一、event事件
events {worker_connections 65536; #设置单个工作进程的最大并发连接数use epoll;#使用epoll事件驱动#xff0c;Nginx支持众多的事件驱动#xff0c;比如:select、poll、epoll#xff0c;只能设置在events模块中设置。accept_mutex on; #on为同一时刻一个…一、event事件
events {worker_connections 65536; #设置单个工作进程的最大并发连接数use epoll;#使用epoll事件驱动Nginx支持众多的事件驱动比如:select、poll、epoll只能设置在events模块中设置。accept_mutex on; #on为同一时刻一个请求轮流由work进程处理,而防止被同时唤醒所有worker,避免多个睡眠进程被唤醒的设置默认为off新请求会唤醒所有worker进程,此过程也称为惊群因此nginx刚安装完以后要进行适当的优化。建议设置为onmulti_accept on; #ON时Nginx服务器的每个工作进程可以同时接受多个新的网络连接此指令默认为off即默认为一个工作进程只能一次接受一个新的网络连接打开后几个同时接受多个。建议设置为on
} 小问题一个服务端最多能接受多少客户端 服务器的硬件配置、操作系统的设置、网络带宽等。在理论上一个服务器可以接受的最大客户端数量是有限的这个数量通常被称为最大并发连接数。然而这个数量可能会受到服务器硬件的限制例如 CPU、内存和网络带宽的限制。此外操作系统的设置也可能会影响这个数量例如操作系统可能会限制一个进程可以打开的文件描述符的数量。 补充 Nginx 是一个 HTTP 和反向代理服务器它主要用于处理 HTTP 请求。它不能直接控制或管理设备的 MAC 地址因为 MAC 地址是设备的物理地址由设备的网络接口硬件决定而不是由软件决定。 反向代理服务器是一种服务器配置它接收客户端的请求然后将这些请求转发给后端服务器最后将后端服务器的响应返回给客户端。 二、 http设置
http 是一个大的语句块包含若干个小的语句块比如server语句块
http {...... #各server的公共配置server { #每个server用于定义一个虚拟主机,第一个server为默认虚拟服务器...}server { ...server_name #虚拟主机名root #主目录alias #路径别名location [OPERATOR] URL { #指定URL的特性...if CONDITION {...}}}
}
http 协议配置说明
http {include mime.types; #导入支持的文件类型,是相对于/apps/nginx/conf的目录default_type application/octet-stream; #除mime.types中文件类型外,设置其它文件默认类型访问其它类型时会提示下载不匹配的类型文件
#日志配置部分#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; #在开启了sendfile的情况下合并请求后统一发送给客户端。#tcp_nodelay off; #在开启了keepalived模式下的连接是否启用TCP_NODELAY选项当为off时延迟0.2s发送默认On时不延迟发送立即发送用户响应报文。#keepalive_timeout 0;keepalive_timeout 65 65; #设置会话保持时间,第二个值为响应首部:keepAlived:timeout65,可以和第一个值不同#gzip on; #开启文件压缩server {listen 80; #设置监听地址和端口server_name localhost; #设置server name可以以空格隔开写多个并支持正则表达式如:*.kgc.com www.kgc.* ~^www\d\.kgc\.com$ default_server #charset koi8-r; #设置编码格式默认是俄语格式建议改为utf-8#access_log logs/host.access.log main;location /fxj { www.ky31.com/fsj /apps/nginx/html root /data;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$ { #以http的方式转发php请求到指定web服务器# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ { #以fastcgi的方式转发php请求到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 Apaches document root# concurs with nginxs one##location ~ /\.ht { #拒绝web形式访问指定文件如很多的网站都是通过.htaccess文件
来改变自己的重定向等功能。# deny all;#}location ~ /passwd.html {deny all;}}# another virtual host using mix of IP-, name-, and port-based configuration##server { #自定义虚拟server
3.3.1 MIME
范例: 识别php文件为text/html# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / { # root html;# index index.html index.htm; #指定默认网页文件此指令由
ngx_http_index_module模块提供# }#}# HTTPS server##server { #https服务器配置# 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;# }#}
2.1 mime
此项为支持的 文件格式如果不支持的格式 会自动帮你下载如果支持 就会显示在网页上
[rootlocalhost ~]#vim /etc/nginx/mime.types
types {text/html html htm shtml;.....................................................................image/png png;image/svgxml svg svgz;image/tiff tif tiff;image/vnd.wap.wbmp wbmp;image/webp webp;image/x-icon ico;image/x-jng jng;image/x-ms-bmp bmp;
2.2 sever 下的 root
root指定了主页文件的位置
root路径格式 指定文件的路径 url
Syntax: root path;
Default:
root html;
Context: http, server, location, 指明 你软件的根目录
写在server中 如果写在location中 检测 location 根据 用户访问地址的不同指定访问的目录 2.3 server块构 建虚拟主机 实际只有1台 好像有多台主机
A 建立独立的配置文件 构建不同虚拟主机 PC端和手机端
第一种基于不同域名的虚拟主机 [rootzzzcentos1 conf.d]#vim /apps/nginx/conf/nginx.conf include /apps/nginx/conf.d/*.conf; 开始编写PC页面 [rootzzzcentos1 conf.d]#mkdir /data/
[rootzzzcentos1 conf.d]#mkdir /data/html
[rootzzzcentos1 conf.d]#echo /data/html /data/html/index.html
[rootzzzcentos1 conf.d]#echo pcpcpc /data/html/index.html
[rootzzzcentos1 conf.d]#cat /data/html/index.html
/data/html
pcpcpc
[rootzzzcentos1 conf.d]#
开始编写手机端页面 server{listen 80;server_name www.m.com;root /mnt/html/;} [rootzzzcentos1 conf.d]#cp pc.conf m.conf
[rootzzzcentos1 conf.d]#ls
m.conf pc.conf
[rootzzzcentos1 conf.d]#vim m.conf
server{listen 80;server_name www.m.com;root /mnt/html/;}
[rootzzzcentos1 conf.d]#mkdir /mnt/html/
[rootzzzcentos1 conf.d]#echo /mnt/html /mnt/html/index.html
[rootzzzcentos1 conf.d]#echo mmmmm /mnt/html/index.html
[rootzzzcentos1 conf.d]#cat /mnt/html/index.html
/mnt/html
mmmmm
[rootzzzcentos1 conf.d]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[rootzzzcentos1 conf.d]#nginx -s reload
测试 我们用了一台主机设置了2个域名 第二种基于不同ip地址 第三种基于不同的端口
2.4 alias 别名
server {listen 80;server_name www.lucky.com;location /news {root /data/nginx/html/pc/;#root 相当于追加 将文件夹news追加到/data/nginx/html/pc/news}location /study {alias /mnt/nginx/sports/;#alias 相当于替换 你访问 study 就是访问/mnt/nginx/sports}
} [rootzzzcentos1 conf.d]#vim pc.conf
server{listen 80;server_name www.lucky.com;root /data/html/;location /shouji {alias /opt/;}
} 检测 实验2 去7-2检测 补充 当这个里面有相同配置的文件按照字母顺序往下读取第一位相同再比较第二位 2.5 location去匹配 追踪url
在一个server中location配置段可存在多个用于实现从url到文件系统的路径映射ngnix会根据用户请求的URI来检查定义的所有location按一定的优化级找出一个最佳匹配而后应用其配置在没有使用正则表达式的时候nginx会先在server中的多个location选取匹配度最高的一个urluri是用户请求的字符串即域名后面的web文件路径然后使用该location模块中的正则url和字符串如果匹配成功就结束搜索并使用此location处理此请求。 location实际是对用户的请求做个性化设置根据用户访问的地址不同指定访问的目录 如果没有对location做定义目录那么会找root目录 location是追踪URL找到资源所在位置 #语法规则
location [ | ~ | ~* | ^~ ] uri { ... } #用于标准url前需要请求字串与uri精确匹配大小敏感,如果匹配成功就停止向下匹配并立即处理请求
^~ #用于标准url前表示包含正则表达式,并且匹配以指定的正则表达式开头,对URI的最左边部分做匹配检查不区分字符大小写
~ #用于标准url前表示包含正则表达式,并且区分大小写
~* #用于标准url前表示包含正则表达式,并且不区分大写
不带符号 #匹配起始于此uri的所有的uri#\ #用于标准url前表示包含正则表达式并且转义字符。可以将 . * ?等转义为普通符号#匹配优先级从高到低
, ^~, ~/~*, 不带符号 匹配越精确优先级越高 匹配优先级从高到低 , ^~ , ~/~*, 不带符号 精确匹配 不带符号 起始于根 ^~ 匹配开头的内容不区分大小写 ~* 包含正则表达式不区分大小写 ~ 包含正则表达式区分大小写 重点哦 优先级比较
题目理解
location / {[ configuration A ]
}location / {[ configuration B ]
}location /documents/ {[ configuration C ]
}
location ^~ /images/ {[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {[ configuration E ]
}
先找出能匹配的项在比较优先级
访问路径选择 题目与答案
第一题 第二题 第三题 第四题 第五题 休息下来点练习 如下请求内容会匹配哪个LocationC http://www.example.com/gallery/images/cat.png A.Location /gallery {} B.Location ~* ^/.(png|jpg)$ {} C.Location ^~ /gallery/images {} D.Location / {}