-->

.htacces-SetEnvIf To NGinx-fastcgi_param Conversio

2019-02-24 03:48发布

问题:

I have below .htaccess settings along with my Apache website; now I am moving this in to Nginx. Thus I wonder how can I put below 'SetEnvIf' parmeters in .htaccess file to Nginx configuraiton? I think its by setting up 'fastcgi_param', please help me to do the conversion.

SetEnvIf HOST albany\.mywebsite\.com MAGE_RUN_CODE=w2760
SetEnvIf HOST albany\.mywebsite\.com MAGE_RUN_TYPE=website
SetEnvIf HOST alexandria\.mywebsite\.com MAGE_RUN_CODE=w1472
SetEnvIf HOST alexandria\.mywebsite\.com MAGE_RUN_TYPE=website
SetEnvIf HOST annarbor\.mywebsite\.com MAGE_RUN_CODE=w2933
SetEnvIf HOST annarbor\.mywebsite\.com MAGE_RUN_TYPE=website

Thank You.

回答1:

you can do it like this:

if ($host = albany.mywebsite.com) {
  env MAGE_RUN_CODE=w2769;
  env $MAGE_RUN_TYPE=website;
}

(and so on for the other host values)

see http://nginx.org/en/docs/ngx_core_module.html#env