Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I thought about rewriting the whole config file for you, however, it would be a bad idea for you to simply copy-paste something from the web like that, and would also probably violate the spirit of StackOverflow answer format.</p> <p>So, let me give you some good pointers of how you can accomplish what you need by yourself, in a general sense.</p> <p>Also, in general, and as far as nginx and performance are concerned, it's not a bad idea to have multiple nearly identical <code>server</code> directives &mdash; they are only bad from the administrative point of view, where it's not very clear to someone looking at them of what's the difference between the servers.</p> <h1><a href="http://nginx.org/r/include" rel="nofollow"><code>include</code></a></h1> <ul> <li><p>You can use the <code>include</code> directive to separate each server into a separate file. This way, anyone looking at your setup can easily use <a href="http://mdoc.su/f/diff.1" rel="nofollow"><code>diff</code></a> to clearly see what's the difference between the servers is, and you could also possibly make changes to one of the server files, and then apply said changes to others with <a href="http://mdoc.su/f/patch.1" rel="nofollow"><code>patch</code></a>, which also brings us to the root cause&hellip;</p></li> <li><p>You can use <code>include</code> to have all the identical parts from each <code>server</code> in a single given file, where each <code>server</code> will then be quite barebone, and will only list the actual differences between the configurations</p></li> </ul> <h1><a href="http://nginx.org/r/set" rel="nofollow"><code>set</code></a></h1> <ul> <li>You can use variables to separate out the values passed to some directives. Note that using all sorts of directives directly within <code>if</code> generally doesn't work, but using an intermediate variable lets you accomplish the same.</li> </ul> <h1>combine <code>include</code> and <code>set</code></h1> <ul> <li>You should probably combine the above ideas to fit your exact need, considering the plans for future growth.</li> </ul> <h1>How do I use <code>set</code> conditionally?</h1> <p>If you wish to fit the whole thing within one <code>server</code>, you can use <code>set</code> conditionally:</p> <pre><code>set $mage_rc "default"; if ($server_name = test1.com) { set $mage_rc "test1"; } location ~ \.php$ { … fastcgi_param MAGE_RUN_CODE $mage_rc; … } </code></pre> <h1>So, where do I start?</h1> <p>With the info you've provided, I would probably keep the servers separate (i.e. still use separate <code>server</code> directives), define some local variables in each <code>server</code>, and <code>include</code> the configuration common to both servers, where in the said common configuration would use the variables like <code>$mage_rc</code>, which should carry on from being defined within each <code>server</code>. With separate <code>server</code>s, there's no need to use <code>if</code> as above &mdash; you'd simply define each variable separately within each <code>server</code>, once for the whole <code>server</code> context.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload