# Rewrite rules for port 80 and 443;

**URL:** <https://www.ruby-forum.com/t/rewrite-rules-for-port-80-and-443/200740>\
**Category:** NGINX\
**Created:** [December 21, 2010, 2:05am UTC](https://www.ruby-forum.com/t/rewrite-rules-for-port-80-and-443/200740 "2010-12-21T02:05:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 21, 2010, 2:05am UTC](https://www.ruby-forum.com/t/rewrite-rules-for-port-80-and-443/200740/1 "2010-12-21T02:05:58Z")

</div>

How am I able to use the same rewrite rule for both port 80 and 443?

It seems like nginx complains if you try to run multiple sites on port  
443 with one cert?

The rewrite rule simple add www. to the domain should a person type the  
domain without it;

Obviously this rule applies using SSL as well;

I dont have solution for this;

Any help would be appreciated;

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [December 21, 2010, 2:31am UTC](https://www.ruby-forum.com/t/rewrite-rules-for-port-80-and-443/200740/2 "2010-12-21T02:31:36Z")

</div>

On 21 Dez 2010 01h06 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How am I able to use the same rewrite rule for both port 80 and 443?

Try this:

server {  
## This is to avoid the spurious if for sub-domain name  
## rewriting. See [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Pitfalls#Server_Name).  
listen [::]:80; # ipv6  
listen [::]:443 ssl; # ipv6  
server\_name [example.com](http://example.com);

```
  ## Server certificate and key.
  ssl_certificate /etc/ssl/certs/example.com-cert.pem;
  ssl_certificate_key /etc/ssl/private/example.com-key.pem;

  ## Use only HTTPS.
  rewrite ^ https://www.example.com$request_uri? permanent;

```

} # server domain rewrite.

> It seems like nginx complains if you try to run multiple sites on  
> port 443 with one cert?

It should, each site needs a _different cert_ or a cert that supports  
several Alternative Names: [www.example.com](http://www.example.com) [www.example.net](http://www.example.net), &c.

Cf. [Configuring HTTPS servers](http://nginx.org/en/docs/http/configuring_https_servers.html)

> The rewrite rule simple add www. to the domain should a person type  
> the domain without it;

See above.

hth,  
— appa
