# Several domains - one IP address

**URL:** <https://community.letsencrypt.org/t/several-domains-one-ip-address/96107>\
**Category:** Help\
**Created:** [June 18, 2019, 6:41pm UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107 "2019-06-18T18:41:03Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![bmw](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bmw/32/7797_2.png) [@bmw](https://community.letsencrypt.org/u/bmw)\
**Post date:** [June 21, 2019, 10:33pm UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/21 "2019-06-21T22:33:37Z")

</div>

I agree with [Apache’s recommendation to use `mod_alias`](https://httpd.apache.org/docs/current/rewrite/avoid.html#redirect) when you simply need to redirect all traffic in a virtual host somewhere else like in their example. With more complex examples and especially with Certbot which needs to take an approach that in theory works with an arbitrary Apache configuration, I do not agree.

In the case of a virtual host like

```auto
<VirtualHost *:80>
  ServerName example1.com
  ServerAlias example2.com www.example1.com www.example2.com
</VirtualHost>

```

Certbot has a few options:

1. We unconditionally redirect all traffic in the virtual host to one of those domains over HTTPS. This is the same as you first example. I don’t think Certbot should be setting up redirects that unexpectedly change the domain though. I expect this will confuse/frustrate users and could in theory even break things because the virtual host could [change behavior based on the domain](https://blogs.apache.org/httpd/entry/new_in_httpd_2_4).
2. We duplicate the virtual host block. This may need to be done once for each domain we want a redirect for as I’m not sure if there’s a good way to dynamically change the target of the redirect based on the domain initially requested over HTTP when using `mod_alias`. We’d then remove all domains we created a new block for from the `ServerName` or `ServerAlias` directives in the original block. This is your second example. This results in a lot of duplication and changes to the user’s config as part of setting up the redirect.
3. We use `mod_rewrite`. This allows us to redirect the traffic to HTTPS by adding a few lines without changing the domain visited or creating duplicate vhosts for the purpose of the redirect.

Hopefully that explanation makes sense. It is true that options 1 or 2 may make more sense for some Apache configurations, but for the sake of simplicity, Certbot always goes with option 3 which I believe to work best in the general case.

---

<div class="post-metadata">

**Author:** ![\_jacek](https://avatars.discourse-cdn.com/v4/letter/_/cc9497/32.png) [@\_jacek](https://community.letsencrypt.org/u/_jacek)\
**Post date:** [June 22, 2019, 2:52am UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/22 "2019-06-22T02:52:01Z")

</div>

Thank you, it is crystal clear now.

I have to say, that I didn’t allow myself to think that someone could have intentions you described, and thus was asking for an example. To me, vhost is the custom part, and include is the common code. Therefore, making from vhosts winnebago containers is just asking for problems due to custom parts creep/split. Again, that is only my preference.

Before continuing, I would like to stress that my http/ssl knowledge is rather limited, plus if I saw httpd.conf files, those were only from the companies I worked for (never worked for a company that was hosting websites, and also didn’t have much to do with IT).

In my last project I decided to use REDIRECT vs. REWRITE, because I read some article that claimed REWRITE potentially may expose more things than REDIRECT (unfortunately, cannot find it anymore, so maybe that is just my memory playing with me). Therefore, apache recommendation for REDIRECT was deemed not just cosmetically nicer, but more secure, and of course simpler to read. That is where I am coming from about preferring REWRITE. That is also what I meant in the previous post that certbot code is having bad logic (if the vhost is simple, e.g., just one TLD, there is no reason to use REWRITE there).

I cannot say that I agree with the argument you are making about two TLDs in one vhost. First, whether we agree on one or the other solution, we are making a decision on behalf of the website owner. Second, in my opinion, your argument is rather a case of having a ‘nicer looking’ (in your opinion) vhost section (not duplicating), vs. having simpler logic vhosts (one vhost serves one purpose - i.e., one TLD, and rest are just aliases, nothing more). In my limited experience, every time I saw more than one TLD in a vhost, it was due to some historical reasons (project name changed, company changed name, was acquired, …). Also, if you assume that one vhost just for the sake of simplicity unifies multiple TLDs but provides different behaviors, you have to also assume that the cost is on the HTML side, where the code must constantly decide which TLD to use… So, that is what sways me into saying that if there are two TLDs in one vhost, the intention (info that certbot is missing) is to unify those, so there is no problem to swap TLD2 to TLD1 when jumping to the ssl part, at the same time the user is conditioned to use forever the new TLD (i.e., 301 error), as such use REDIRECT. This is the case of certbot missing information/intentions,

However, as I said, I don’t have any stats to show that yours or mine assumptions about having multiple TLDs in one vhost are more prevalent, so go with what you know.

I think that we are good now, we both understand all intentions / implications. Also, thank you for taking your time to get me to appreciate more this topic!

---

<div class="post-metadata">

**Author:** ![jfines](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@jfines](https://community.letsencrypt.org/u/jfines)\
**Post date:** [June 24, 2019, 1:25am UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/23 "2019-06-24T01:25:01Z")

</div>

For what it’s worth…

I recently went through the process of trying to add a second domain to the same (linode / ubuntu 18.04) server. In my case I attempted to create a second virtual hosts file for the second domain (2 individual virtual hosts config files for the 2 domains). The solution that worked for me was…

[1]: Created a cert.conf configuration file for use to get certs for ip only. (with Apache2 use a2ensite and a2dissite) to enable disable.

- the configuration file contains only port 80 configured virtual hosts (one for each subdomain + one for the primary domain).
- the configuration file contains the virtual hosts config for both domains (in the one, single file).  
[2]: Perform the steps to obtain the certs using certbot  
[3[: Create separate / individual files for each domain (one for each) and add the port 443 (secure) configuration into each domain’s config file along with the original port 80 configuration content.  
[4]: Add redirects as desired

Worked in my case  
HTH Someone

---

<div class="post-metadata">

**Author:** ![nu11secur1ty](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/nu11secur1ty/32/22917_2.png) [@nu11secur1ty](https://community.letsencrypt.org/u/nu11secur1ty)\
**Post date:** [June 25, 2019, 11:04am UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/24 "2019-06-25T11:04:23Z")

</div>

# With multiple domains using one IP address

1. Register your domain [blabla.com](http://blabla.com) in your root server.
2. Telling of your root server that you want to registered a wild card domain, for example:  
\*[blaba.com](http://blaba.com).
3. In that way, you can use a lot of domains using your parent domain [blaba.com](http://blaba.com) “[something.blabla.com](http://something.blabla.com)”.
4. Create a virtual host file and describe your parent domain [blabla.com](http://blabla.com), and every subdomain.
5. You can use a different root server to register a different domain on one IP address 😉

- vhost: example using one domain with subdomains:

# [blabla.com](http://blabla.com)

\<VirtualHost 192.168.1.15:80\>  
DocumentRoot “/home/user\_name/your\_web\_project/htdocs”  
ServerName [blabla.com](http://blabla.com)  
ServerAlias [www.blabla.com](http://www.blabla.com)

######################################################################

# [some.blabla.com](http://some.blabla.com)

\<VirtualHost 192.168.1.15:80\>  
DocumentRoot “/home/user\_name/your\_web\_project/htdocs”  
ServerName [some.blabla.com](http://some.blabla.com)  
ServerAlias [www.some.blabla.com](http://www.some.blabla.com)

When you decide to obtain your two domain on the same IP  
you must be obtaining them multiply, or I recommend you one by one.

- Example of multiple  
./certbot-auto certonly --standalone -d [some.blabla.com](http://some.blabla.com) -d [blabla.com](http://blabla.com)

- Example of single using WWW and None WWW  
./certbot-auto certonly --standalone -d [www.blabla.com](http://www.blabla.com) -d [blabla.com](http://blabla.com)

* * *

# With multiple IP addresses using one domain

Round Robin my friend 😉  
Link: [https://en.wikipedia.org/wiki/Round-robin\_DNS](https://en.wikipedia.org/wiki/Round-robin_DNS) 🙂  
And when you decide to obtain you cert of your domain [blabla.com](http://blabla.com) you will be obtaining the cert without any problem, but the only different cases are that you use two IP addresses.

When you use “dig [blalba.com](http://blalba.com)” you will see this if you already describe these two IP addresses in to  
your DNS Zone.

;; ANSWER SECTION:  
[blabla.com](http://blabla.com). 6791 IN A 0.0.0.0  
[blabla.com](http://blabla.com). 6791 IN A 0.0.0.0  
Two IP’s for the same domain

You must tell of your root server where you register your domain [blabla.com](http://blabla.com) that you use two IP address. And you must describe it, on this domain DNS zone!!! 😉  
BR

---

<div class="post-metadata">

**Author:** ![\_jacek](https://avatars.discourse-cdn.com/v4/letter/_/cc9497/32.png) [@\_jacek](https://community.letsencrypt.org/u/_jacek)\
**Post date:** [June 27, 2019, 5:18am UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/25 "2019-06-27T05:18:28Z")

</div>

Brad,

> [@bmw](#):
>
> In your first example, [http://example2.com](http://example2.com) will redirect to [https://example1.com](https://example1.com). This will not cause an error and if you’re OK with the domain change, this works just fine.

I guess, that _will_ cause an error or rather break HSTS, after all.

Again, assuming that we have a following vhost:

```
<VirtualHost *:80>
  ServerName www.example.com
  ServerAlias example.com
  Redirect permanent / https://www.example.com/
</VirtualHost>

```

and we enable HSTS on the SSL side. When someone enters [http://example.com](http://example.com), that basically kills HSTS (as far as I understand it), as Redirect changes DNS name before redirecting to HTTPS protocol. I guess, the same will happen if on the ServerAlias line we have something like [old-example.com](http://old-example.com). If my understanding of it is correct, then my previous arguments about having just one Redirect in a combined ServerName/ServerAlias vhost are invalid. Of course, there are two solutions to that (that you have already mentioned). Either to break down that combined vhost into multiple ones, or have multiple Rewrite in that single vhost (you of course already indicated that you don't like those smaller vhosts 🙂

Thank you, Jacek

---

<div class="post-metadata">

**Author:** ![\_jacek](https://avatars.discourse-cdn.com/v4/letter/_/cc9497/32.png) [@\_jacek](https://community.letsencrypt.org/u/_jacek)\
**Post date:** [June 29, 2019, 4:05am UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/27 "2019-06-29T04:05:15Z")

</div>

If my understanding of ‘permanent’ is correct, the ‘No’ case will violate HSTS only once, as the browser will take note about that redirect, and will not be hitting HTTP part anymore. Where, your ‘Yes’ case will cause HSTS violation every time a given user will go to that ‘[http://example.com](http://example.com).’ Unless I am missing something here.

---

<div class="post-metadata">

**Author:** ![\_jacek](https://avatars.discourse-cdn.com/v4/letter/_/cc9497/32.png) [@\_jacek](https://community.letsencrypt.org/u/_jacek)\
**Post date:** [June 29, 2019, 6:32am UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/29 "2019-06-29T06:32:40Z")

</div>

First, if you check the context of that example, there is no mod\_rewrite involved.  
Second, both lines are syntactically correct. Your ‘Yes’ line just implies ‘temp’ is used in place of ‘permament’  
Third, in both cases, whether 301 or 302 is needed, it is not for apache, but to convey to the browser what your intentions are.  
[https://httpd.apache.org/docs/current/mod/mod\_alias.html#redirect](https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect)

However, if you think that there are some implications when mod\_rewrite is also needed, a link to apache docs would be nice.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/letsencrypt/original/3X/c/a/ca6c06ea1ea201324bba7048c6841ce60236468d.png) [@system](https://community.letsencrypt.org/u/system)\
**Post date:** [July 29, 2019, 6:35am UTC](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107/30 "2019-07-29T06:35:13Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[Previous page](https://community.letsencrypt.org/t/several-domains-one-ip-address/96107.md?page=1)
