lucky_apple_orance 2022-10-30 00:40 采纳率: 0%
浏览 41

nginx,rewrite配置

1,我的配置文件中写的rewrite如下

    location  /lucy/ {
            rewrite ^/lucy/(.*)$ /lucy/access/$1 break;
            #rewrite .* /lucy/access/a/b/index.html break;
            root /tmp/data/luxin/;
            index index.html index.htm;
    }

1
2
3
4
5
6
7
网站的网页目录如下

[root@nginx b]# pwd
/tmp/data/luxin/lucy/access/a/b
[root@nginx b]# ls
index.html
1
2
3
4
访问方法

[root@centos07 ~]# curl -v -L 192.168.100.108/lucy/a/b/
1
本人认为我在访问时匹配到/lucy的location项,然后地址重写到/lucy/access/a/b,然后再次访问这个url,但为什么访问404呢?求解答
错误日志如下:

2022/10/28 23:19:27 [error] 35214#0: *276 open() "/tmp/data/luxin/lucy/access/access/a/b/index.html" failed (2: No such file or directory), client: 192.168.100.107, server: 192.168.100.108, request: "GET /lucy/a/b/ HTTP/1.1", host: "192.168.100.108"
2022/10/28 23:19:33 [error] 35214#0: *277 "/tmp/data/luxin/lucy/access/access/a/b/index.html" is not found (2: No such file or directory), client: 192.168.100.107, server: 192.168.100.108, request: "GET /lucy/access/a/b/ HTTP/1.1", host: "192.168.100.108"
1
2
为什么会多一个access目录,break不应该就匹配一次就结束了吗?

  • 写回答

1条回答 默认 最新

  • 狂龙骄子 2022-10-30 11:47
    关注

    rewrite 意思是转发,因为是匹配 uri /lucy/, rewrite 中的 绝对路径配置需要调整下:

        location  /lucy/ {
            # rewrite ^/lucy/(.*)$ /lucy/access/$1 break;
            rewrite ^/lucy/(.*)$ /lucy/$1 break;
            # root /tmp/data/luxin/;
            root /tmp/data/luxin;
            index index.html index.htm;
        }
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 10月30日

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题