nginx location 配置(代理本地文件)

 

 

复制代码
 worker_processes  4; //子进程的进程数量
 ps -ef | grep nginx 查看nginx进程
 //worker_cpu_affinity 0001 0010 0100 1000;
/*nginx所在主机拥有4核cpu,那么worker_ processes的值通常不会大于4,这样做的原因是为了尽力让每个worker进程都有一个cpu可以使用,尽量避免了多个worker进程抢占同一个cpu的情况,我们也可以将worker_ processes的值设置为"auto"*/
00000001 00000010 
01 10
events {
    worker_connections  1024; //单个业务进程可接受连接数 
    //connections不是随便设置的,而是与两个指标有重要关联,一是内存,二是操作系统级别的“进程最大可打开文件数”
    //内存:每个连接数分别对应一个read_event、一个write_event事件,一个连接数大概占用232字节,2个事件总占用96字节,那么一个连接总共占用328字节,通过数学公式可以算出100000个连接数大概会占用 31M = 100000 * 328 / 1024 / 1024,当然这只是nginx启动时,connections连接数所占用的nginx
    //进程最大可打开文件数:ulimit -n
}

http {
    //引入http mime类型 和浏览器的Content-Type的有关系
    include       mime.types; 
    //如果mime类型没匹配上,默认使用二进制流的方式传输
    default_type  application/octet-stream;
    sendfile        on;
    //使用linux的 sendfile(socket, file, len) 高效网络传输,也就是数据0拷贝。
    keepalive_timeout  65;//保持连接,超时时间。秒
    server {
        listen       7070; //监听端口号
        server_name  10.2.2.49; //#域名、主机名
        location /cache_app { //匹配路径
            root html/; // 文件根目录
            index  index.html index.htm; //默认页名称
        }
        location /rise {
            alias html/cache_app;
            index index.html index.htm;
        }
        location / {
            root html/screen;
            index index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html; //报错编码对应页面
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       7071; //监听端口号
        server_name  10.2.2.49; //#域名、主机名
        location /cache_app { //匹配路径
            root /data/html/rise; // 文件根目录
            index  index.html index.htm; //默认页名称
        }
    }
    include servers/*;

复制代码
 
  • 路径匹配规则
复制代码
#访问:http://localhost/
#匹配规则:
location = / {
   #规则A
}
 
#访问:http://localhost/login
#匹配规则:
location = /login {
   #规则B
}
 
#访问:http://localhost/static/a.html
#匹配规则:
location ^~ /static/ {
   #规则C
}
 
#访问:http://localhost/a.gif、http://localhost/b.jpg
#匹配规则:
location ~ \.(gif|jpg|png|js|css)$ {
   #规则D
}
 
#访问:http://localhost/a.PNG
#匹配规则:
location ~* \.png$ {
   #规则E
}
 
#访问:http://localhost/register、http://localhost/category/id/1111
#匹配规则:
location / {
   #规则F
}
复制代码

 

posted @   SimoonJia  阅读(1691)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示