# Problem about config one virtual host with separated server blocks

**URL:** <https://www.ruby-forum.com/t/problem-about-config-one-virtual-host-with-separated-server-blocks/194521>\
**Category:** NGINX\
**Created:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/problem-about-config-one-virtual-host-with-separated-server-blocks/194521 "2010-09-06T16:39:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/problem-about-config-one-virtual-host-with-separated-server-blocks/194521/1 "2010-09-06T16:39:56Z")

</div>

Is it possible to write a config like this?

server {  
server\_name [www.example.com](http://www.example.com);  
location / {  
…  
}  
}

server {  
server\_name [www.example.com](http://www.example.com);  
listen 143;  
ssl on;  
ssl\_certificate example.crt;  
ssl\_certificate\_key example.key;  
}

That means I can config one domain with two separated server blocks.  
This feature is handy thus I can write a config auto-gen script.

Thanks.

Posted at Nginx Forum:

> **[Problem about config one virtual host with separated server blocks](https://forum.nginx.org/read.php?2,127215,127215#msg-127215)**
>
> Is it possible to write a config like this? server { server\_name www.example.com; location / { ... } } server { server\_name www.example.com; listen 143; ssl on; ssl\_certi

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [September 6, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/problem-about-config-one-virtual-host-with-separated-server-blocks/194521/2 "2010-09-06T16:44:10Z")

</div>

On Sat, Sep 04, 2010 at 11:52:28PM -0400, speedfirst wrote:

> Is it possible to write a config like this?
> 
> server {  
> server\_name [www.example.com](http://www.example.com);  
> location / {  
> …  
> }  
> }
> 
> server {  
> server\_name [www.example.com](http://www.example.com);  
> listen 143;  
> ssl on;  
> ssl\_certificate example.crt;  
> ssl\_certificate\_key example.key;  
> }
> 
> That means I can config one domain with two separated server blocks.  
> This feature is handy thus I can write a config auto-gen script.

> **[Configuring HTTPS servers](http://nginx.org/en/docs/http/configuring_https_servers.html#single_http_https_server)**
>
> To configure an HTTPS server, the ssl parameter must be enabled on listening sockets in the server block, and the locations of the server certificate and private key files should be specified:

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [September 6, 2010, 4:51pm UTC](https://www.ruby-forum.com/t/problem-about-config-one-virtual-host-with-separated-server-blocks/194521/3 "2010-09-06T16:51:47Z")

</div>

Thanks for the reply, but I’m think you misunderstand my question. The  
question is NOT whether I can use multiple “server” blocks. What I to  
know is whether Nginx will merge multiple “server” blocks, which share  
the same listen and server name, into the single one. This is just like  
the “partial class” grammar in C#.

Posted at Nginx Forum:

> **[Re: Problem about config one virtual host with separated server blocks](https://forum.nginx.org/read.php?2,127215,127489#msg-127489)**
>
> Is it possible to write a config like this? server { server\_name www.example.com; location / { ... } } server { server\_name www.example.com; listen 143; ssl on; ssl\_certi

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [September 6, 2010, 4:52pm UTC](https://www.ruby-forum.com/t/problem-about-config-one-virtual-host-with-separated-server-blocks/194521/4 "2010-09-06T16:52:23Z")

</div>

On Sun, Sep 05, 2010 at 09:56:08PM -0400, speedfirst wrote:

> Thanks for the reply, but I’m think you misunderstand my question. The  
> question is NOT whether I can use multiple “server” blocks. What I to  
> know is whether Nginx will merge multiple “server” blocks, which share  
> the same listen and server name, into the single one. This is just like  
> the “partial class” grammar in C#.

No, nginx does not merge server blocks.  
nginx merges only “http” \> “server” \> “location”.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
