我尝试从 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
}
}
要修复错误,您需要像这样更改重写。
location = /index.php {
rewrite ^/id-(.*)$ /index.php?id=$1 last;
}
希望对你有帮助。