/etc/nginx/sites-enabled/default linux nginx 服务器中的无效变量名

问题描述 投票:0回答:1

我尝试从 nginx 重写 url 但显示 nginx 错误日志
> [emerg] 225048#225048: invalid variable name in /etc/nginx/sites-enabled/default:1276

server {
    root /var/www/mypath/2ndpaht/domain/public;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name domain_name.com;

    location / {
     try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }
    location ~ /\.ht {
        deny all;
    }

    location = /index.php {
        rewrite index.php?id=$1 ^id-(.*)$ break; # error this line
    }
}

重写 index.php?id=$1 ^id-(.*)$ break;行号 1276
谢谢
regex nginx nginx-config nginx-location
1个回答
0
投票

要修复错误,您需要像这样更改重写。

location = /index.php {
    rewrite ^/id-(.*)$ /index.php?id=$1 last;
}

希望对你有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.