gpt4 book ai didi

regex - Nginx server_name 正则表达式不作为变量工作

转载 作者:可可西里 更新时间:2023-11-01 16:08:05 28 4
gpt4 key购买 nike

有没有人告诉我为什么我仍然有这样的错误?

Restarting nginx: [emerg]: unknown "domain_name" variable
configuration file /etc/nginx/nginx.conf test failed

变量所在的代码部分如下所示:

server {
# if you're running multiple servers, instead of "default" you should
# put your main domain name here
listen 80 default;

# you could put a list of other domain names this application answers
server_name ^~(?<domain_name>[^\.]*)\.(?<tld>[^\.]*)$;

# root defined by domain
root /home/deployer/apps/$domain_name/current/;

# access && error && rewrite log
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
rewrite_log on;

# default location
location / {

...

最佳答案

删除“^”。来自

server_name ^~(?<domain_name>[^\.]*)\.(?<tld>[^\.]*)$;

server_name ~(?<domain_name>[^\.]*)\.(?<tld>[^\.]*)$;

或者切换“^”和“~”。字母“~”必须在第一个。

server_name ~^(?<domain_name>[^\.]*)\.(?<tld>[^\.]*)$;

关于regex - Nginx server_name 正则表达式不作为变量工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15578574/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com