codersofthedark
codersofthedark

Reputation: 9655

What is the most optimized way to define server blocks in nginx config?

I have fifteen virtual hosts (servers) with separate log location for it. I am a bit confused about which would be the best option to write nginx config file for each. All server blocks in one file or a separate file for each server?

Which would be a more efficient way?

Upvotes: 2

Views: 77

Answers (3)

Pierre L.
Pierre L.

Reputation: 11

If there's some commonality between your virtual hosts configs, such as general SSL settings or denying certain types of requests, you may want to use includes.

I like to keep separate vhosts config files, it's easier to take one domain offline for maintenance for instance.

Upvotes: 1

Alexey Ten
Alexey Ten

Reputation: 14374

Nginx reads config once on start (or reload), so do whatever is more appropriate for you.

I would write related server blocks together in one file, and have one bunch of related servers per file.

Or have one file per server.

Or write them all in one file.

Upvotes: 2

Barandeep Singh
Barandeep Singh

Reputation: 31

Efficiency is not effected by how you define the blocks in nginx. Thus, it would be same in the given case.

Upvotes: 1

Related Questions