Nginx unknown directive "if ($ domain"

Nginx Complains about the following part of my configuration:

nginx: [emerg] unknown directive "if($domain" in /etc/nginx/nginx.conf:38 nginx: configuration file /etc/nginx/nginx.conf test failed 

Here is the bit he is talking about:

 server_name ~^(?:(?<subdomain>\w*)\.)?(?<domain>\w+)\.(?<tld>(?:\w+\.?)+)$; if($domain = "co") { set $domain "${subdomain}"; set $subdomain "www"; set $tld "co.${tld}"; } if ($subdomain = "") { set $subdomain "www"; } root /var/www/sites/$domain.$tld/$subdomain; location / { index index.php index.html index.htm; } 

Here is the complete server section of my configuration file:

 server { listen 80; server_name ~^(?:(?<subdomain>\w*)\.)?(?<domain>\w+)\.(?<tld>(?:\w+\.?)+)$; if($domain = "co") { set $domain "${subdomain}"; set $subdomain "www"; set $tld "co.${tld}"; } if ($subdomain = "") { set $subdomain "www"; } root /var/www/sites/$domain.$tld/$subdomain; location / { index index.php index.html index.htm; } } # pass the PHP s to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

What is the problem?

+6
source share
1 answer

I hope you decide to solve this, but for those who are struggling with a similar problem. You need to specify a space between the if statement and the opening bracket.

So in your example you need to change the line

 if($domain = "co") { 

to

 if ($domain = "co") { 

And everything should work fine.

+35
source

Source: https://habr.com/ru/post/959043/


All Articles