首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Openresty 配置访问静态文件,拆分路径

Openresty 配置访问静态文件,拆分路径

作者头像
Devops海洋的渔夫
发布2019-05-31 10:59:15
2.3K0
发布2019-05-31 10:59:15
举报
文章被收录于专栏:Devops专栏Devops专栏
http {
    server {
        listen 8080;
        location / {
           # default_type text/html;
           # content_by_lua '
           #     ngx.say("<p>hello, world</p>")
           # ';
            root   /work/moniter-web/web/redis;
            index  index.html index.htm;
        }

        location /ngx_status {
        stub_status on;
        access_log off;
        }
    }
}

这种配置静态文件,直接就是锁死了所有的 / 目录请求,访问这个URL即可,如下:

curl 127.0.0.1:8080/index.html

那么如果,我想要根据前面的路径再拆分一下请求呢? 例如:我有另一个工作目录/work/moniter-web/web/redis,需要访问另一个子路径url(/redis/index.html)命中这个工作目录下的index.html ,那么该怎么配置呢?

http {
    server {
        listen 8080;
        location / {
            default_type text/html;
            content_by_lua '
                ngx.say("<p>hello, world</p>")
            ';
        }

        location /redis {
            #root   /work/moniter-web/web/redis;
            root   /work/moniter-web/web;
            index  index.html index.htm;
        }

        location /ngx_status {
            stub_status on;
            access_log off;
        }
    }
}

可以看到,拆分路径的redis的绝对路径不能写到redis,不然路径就会找不到。

测试请求的URL如下:

curl 127.0.0.1:8080/redis/index.html
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.05.04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档