# Merge HTTP & HTTPS Definition In The Same Section

**URL:** <https://www.ruby-forum.com/t/merge-http-https-definition-in-the-same-section/182818>\
**Category:** NGINX\
**Created:** [February 3, 2010, 8:22am UTC](https://www.ruby-forum.com/t/merge-http-https-definition-in-the-same-section/182818 "2010-02-03T08:22:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaoxing](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/74df32/32.png) [@Yaoxing](https://www.ruby-forum.com/u/Yaoxing)\
**Post date:** [February 3, 2010, 8:22am UTC](https://www.ruby-forum.com/t/merge-http-https-definition-in-the-same-section/182818/1 "2010-02-03T08:22:01Z")

</div>

## Hi all, I’m wondering if it’s possible to merge the HTTP and HTTPS definition into one section. The situation is like this, my server serves both HTTP and HTTPS, both of them have the same redirecting rules. I don’t want to define them in 2 places. I looked up the document and find that it is possible to bind both HTTP & HTTPS ports in the same “server” section like this: listen 80; listen 443 default ssl; but in this way how can I define stuff related to SSL? Such as certifications etc.? I tried if ($server\_ports = 443) { ssl on; ssl\_certificate /etc/ssl/abc.pem; ssl\_certificate\_key /etc/ssl/abc.key; ssl\_session\_timeout 5m; ssl\_protocols SSLv2 SSLv3 TLSv1; ssl\_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl\_prefer\_server\_ciphers on; } but i’m told that “ssl” directive is not allowed here Could anyone tell me how to do it? Thanks for help.

Regards,  
Yaoxing

---

<div class="post-metadata">

**Author:** ![Yaoxing](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/74df32/32.png) [@Yaoxing](https://www.ruby-forum.com/u/Yaoxing)\
**Post date:** [February 3, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/merge-http-https-definition-in-the-same-section/182818/2 "2010-02-03T14:51:48Z")

</div>

Am 03.02.2010 um 08:21 schrieb Yaoxing:

> I’m wondering if it’s possible to merge the HTTP and HTTPS definition  
> into one section.  
> I would prefer a include file.  
> ssl\_certificate /etc/ssl/abc.pem;  
> ssl\_certificate\_key /etc/ssl/abc.key;  
> ssl\_session\_timeout 5m;  
> ssl\_protocols SSLv2 SSLv3 TLSv1;  
> ssl\_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;  
> ssl\_prefer\_server\_ciphers on;  
> }

* * *

server.conf

server {  
listen 80;  
include server\_def.conf;  
}

## server { listen 443; ssl on; ssl\_certificate /etc/ssl/abc.pem; ssl\_certificate\_key /etc/ssl/abc.key; … include server\_def.conf; }

server\_def.conf

## server\_name [domain.com](http://domain.com); index index.php; …

This way I include nearly anything reusable. (eg. drupal-conf)

Micha

---

<div class="post-metadata">

**Author:** ![Yaoxing](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/74df32/32.png) [@Yaoxing](https://www.ruby-forum.com/u/Yaoxing)\
**Post date:** [February 3, 2010, 2:53pm UTC](https://www.ruby-forum.com/t/merge-http-https-definition-in-the-same-section/182818/3 "2010-02-03T14:53:34Z")

</div>

On Wed, Feb 03, 2010 at 03:21:12PM +0800, Yaoxing wrote:

> certifications etc.? I tried  
> “ssl” directive is not allowed here  
> Could anyone tell me how to do it?

> **[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:** ![Yaoxing](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/74df32/32.png) [@Yaoxing](https://www.ruby-forum.com/u/Yaoxing)\
**Post date:** [February 5, 2010, 3:48am UTC](https://www.ruby-forum.com/t/merge-http-https-definition-in-the-same-section/182818/4 "2010-02-05T03:48:09Z")

</div>

Got your idea. Thanks to Micha and Igor.

Regards,  
Yaoxing
