nginx index inside conditional location


On a server that delivers multiple sites, I need to set up the location of a request depending on the host. For example I need to serve different text depending on the site language.


The only problem here is that inside the location declaration there cannot be a root or index defined inside an if clause. The way to do it is to set up a variable from the if clause and use it outside of the if:

location /subpage/ {
if ($http_host = “”) { set $country “fr”; }
if ($http_host = “”) { set $country “es”; }
index /local/files/$country/index.html

About admin

Just another php developer trying to give something back to the community.
This entry was posted in Best practices, nginx, System and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s