nginx中的$rule_0 1$rule_0 是什么意思?

server {
        listen        80;
        server_name  www.baidu.com;
        root   "xxx/frontend";
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With,Authorization,Content-Type,access-token,bloc-id,store-id;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE;
        location / {
            index index.php index.html error/index.html;
            error_page 400 /error/400.html;
            include D:/nginx.htaccess;
            autoindex  off;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   192.168.0.1;
            fastcgi_index  index.php;
        }
        location /api {
            index index.php index.html;
            if (!-e $request_filename)
            {
                rewrite ^/api/(.*)$ /api/index.php last;
            }
            if (!-f $request_filename){
                set $rule_0 1$rule_0;
            }
        }

        location /admin {
            index index.php index.html;
            if (!-e $request_filename)
            {
                rewrite ^/admin/(.*)$ /admin/index.php last;
            }
            if (!-f $request_filename){
                set $rule_0 1$rule_0;
            }
        }
        
         location /help {
            index index.php index.html;
            if (!-e $request_filename)
            {
                rewrite ^/help/(.*)$ /help/index.php last;
            }
            if (!-f $request_filename){
                set $rule_0 1$rule_0;
            }
        }
}

还有一个问题 我看这里写了3个 index index.php index.html 这种写3个代表了什么
是按照顺序找么?

nginx.htaccess
好像是这个

if (!-f $request_filename){
    set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
    rewrite /.* /index.php;
}
阅读 1.1k
1 个回答

$rule_0 是不是在 D:/nginx.htaccess 设置了,发下这个文件详情

index index.php index.html 第一个 index 是 nginx 指令,后面 index.php index.html 是表示按先后顺序默认访问哪个文件,即先访问 index.php 如果没有这个文件就访问 index.html

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题