Nginx server_name regexp不作为变量 [英] Nginx server_name regexp not working as variable

查看:394
本文介绍了Nginx server_name regexp不作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人告诉我为什么我还是有这样的错误?

Is there anybody who tell me why i still got error like this?

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

的代码其中是变量看起来像:

the part of code where is variable looks like:

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>[^\.]*)$;

或切换^和〜。 〜必须是第一个。

Or switch "^" and "~". The letter "~" must be the first one.

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

这篇关于Nginx server_name regexp不作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆