nginx index inside conditional location

Description:

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.

Solution:

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 = “mysite.fr”) { set $country “fr”; }
if ($http_host = “mysite.es”) { set $country “es”; }
index /local/files/$country/index.html
}

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s