![](https://img-blog.csdnimg.cn/20190927151026427.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Nginx学习笔记
Nginx学习笔记
刘远山
日积月累
展开
-
Nginx Location指令与匹配规则使用
Location语法结构:location [ = | ~ | ~* | ^~ ] /uri/ { configuration }Location本身:192.168.2.1/home/index.php?id=10Location运算符:location = / 精确前缀匹配。192.168.2.1192.168.2.1/location ^~ /home 普通字符串匹配。192.168.2.1/home192.168.原创 2021-11-07 20:02:12 · 330 阅读 · 0 评论 -
Nginx Stub_status查看状态与Sub_module内容替换
Stub_status查看状态开启Stub_status模块:有–with-http_stub_status_module说明已经开启该模块/usr/local/nginx/sbin/nginx -V#Stub_status模块使用:location /status { stub_status;}结果分析:1.Active connections: 21)The current number of active client connections including Wait原创 2021-01-16 16:34:21 · 305 阅读 · 0 评论 -
Nginx Rewrite重写技术
Nginx Rewrite重写技术Rewrite语法:rewrite {规则} {定向路径} {重写类型}rewrite ^/(.*) http://www.test.com/$1 permanent;Rewrite重写类型:last 相当于Apache里的[L]标记,表示完成rewritebreak 本条规则匹配完成后,终止匹配,不再匹配后面的规则redirect 返回302临时重定向,浏览器地址会显示跳转后的URL地址permanent原创 2021-01-16 20:09:52 · 167 阅读 · 0 评论 -
Nginx Basic_module用户认证
Basic_module用户认证安装支持htpasswd命令的软件yum -y install httpd-tools#生成htpasswd密码文件htpasswd -bc /usr/local/nginx/html/pass.db admin 123Basic模块使用:auth_basic "http://106.52.36.65";auth_basic_user_file /usr/local/nginx/html/pass.db;使用: location /status原创 2021-01-16 18:00:50 · 117 阅读 · 1 评论 -
Nginx性能优化
Nginx进程与线程模式1.进程线程模式:主进程(一个主进程对应多个worker进程)->多Worker工作进程(worker数量一般等于Cpu核数量,每一个woker线程会开一个线程一对一关系)->单线程(默认)2.内存消耗极低Linux下设置单用户并发打开文件数一个woker进程默认支持1024个线程并发,而Linux系统模式支持用户并发处理1024个文件,如果需要提高nginx并发数,需要优先提高Linux并发处理文件数1.查看ulimit -n2.设置(提高Linux并原创 2021-11-07 16:03:58 · 1692 阅读 · 0 评论 -
Nginx配置虚拟主机(即:域名)
配置dns本地域名解析表C:\Windows\System32\drivers\etc\hosts192.168.56.10 php.test.com测试域名解析ping php.test.comnginx配置虚拟主机http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65;原创 2021-11-06 20:54:09 · 771 阅读 · 0 评论 -
Nginx中Return指令使用
Return指令使用:1、返回状态码return 404;location /test { set $name 'user123'; return 404 $name; } curl -i http://192.168.56.10/test2、返回字符串(不过输出结果并未见到 状态码后的字符串输出)return 200 ‘hello’;location /test { ret原创 2021-11-06 20:27:04 · 12794 阅读 · 0 评论 -
客户端访问Nginx服务权限控制
Nginx服务权限控制allow 允许访问IPallow 192.168.2.3;允许所有访问allow all;deny 拒绝某个IP地址访问deny 192.168.2.3;拒绝所有访问deny all;示例:拒绝192.168.56.1访问本服务location / { index index.html index.php index.htm; deny 192.168.56.1; allow all原创 2021-11-06 19:46:37 · 1434 阅读 · 0 评论 -
Nginx 配置文件详解与常用内置变量
nginx.conf配置文件详解#进程守护者:user nginx;#错误日志error_log logs/error.log;#pid进程信息:pid logs/nginx.pid;#worker进程数:(约等于CUP核数,单核就设置1)worker_processes 1;#每进程处理连接数:worker_connections 1024;#主配置区域结构:http{ #mime文件类型 include mime.types;原创 2021-01-16 15:09:15 · 458 阅读 · 0 评论 -
Nginx反向代理实例与负载均衡实现
$args 请求中的参数location /echo1 { echo $args; }#验证curl -d "name=user1&pass=123" -G http://192.168.56.10/echo1$binary_remote_addr 远程地址的二进制表示location /echo1 { echo $binary_remote_addr;原创 2021-11-06 15:58:35 · 688 阅读 · 0 评论 -
Nginx动态增加Echo模块与使用
Nginx动态增加Echo模块查看Nginx编译模块:/usr/local/nginx/sbin/nginx -V--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module安装Echo模块:#下载地址https://github.com/openresty/echo-nginx-modu原创 2021-11-06 15:21:38 · 812 阅读 · 0 评论 -
Nginx源码安装与调试常用命令
目录1.Nginx安装2.Nginx服务管理3.Nginx进程管理4.Nginx端口管理5.Nginx Web服务器测试Nginx安装1、准备依赖包:yum -y install zlib-devel pcre-devel openssl-devel gcc2、准备nginx用户:(用于进程间通信)useradd -M -s /sbin/nologin nginxid nginx 3、源码编译与安装: (–with-http_stub_status_module:开启进程树查看原创 2021-10-31 17:23:49 · 392 阅读 · 0 评论