Nginx server_name regexp不能用作变量

前端之家收集整理的这篇文章主要介绍了Nginx server_name regexp不能用作变量 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

有谁告诉我为什么我仍然会出现这样的错误

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>[^\.]*)$;
原文链接:https://www.f2er.com/nginx/532402.html

猜你在找的Nginx相关文章