How should I configure multiple virtual hosts with a single configuration file in Apache?When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt?Redirect people after SSL is set upBreaking links with apache2 after SSL installationCorrectly setup apache virtual hosts with multiple usersIP redirection for apache in virtual hostsApache server virtual hosts not workingApache Web Server Configuration to install Owncloud 8.2.2 on Ubuntu 14.04Redirecting url to custom directoryHow to disable non-SSL on Apache on only the host without disabling in virtual hosts?installing a wildcard Certificate on a subdomain running on ubuntuApache2 HTTP Ubuntu Won't Restart

Finding how much time it takes for a complete Earth revolution around the Sun

Does a Thief rogue's Fast Hands allow you to drink a potion as a bonus action?

Three Tongues of Rock

If thermodynamics says entropy always increases, how can the universe end in heat death?

Is there any obvious warning when auto-pilot is disengaged or when the mode changes?

Can I hook up a single phase switch to an electric wood splitter?

Why does all female physical beauty have to be sexualised?

How can I deal with my coworkers using unknown jargon and acronyms?

Does Burrow leave behind a tunnel?

Difference between a paintmap and wetmap

Writing style in academic English

Character Development - Robert Baratheon

Clockwise matrix rotation

Could a chess engine do retro analysis?

Sending non-work emails to colleagues. Is it rude?

Is there a spell, magical item, or any other method to accurately calculate how long ago an object/construct was created?

Commander Damage Stacking & Player Control

Is Communism intrinsically Authoritarian?

Will transcribing music improve my ability to play a song by ear?

TikZ: How to draw a pattern at the border of a not closed tikz path

Captain Pun's new boat

Dropping "to be" and other verbs in Latin?

How to verify router firmware is legit?

Is there an appropriate response to "Jesus Loves You"?



How should I configure multiple virtual hosts with a single configuration file in Apache?


When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt?Redirect people after SSL is set upBreaking links with apache2 after SSL installationCorrectly setup apache virtual hosts with multiple usersIP redirection for apache in virtual hostsApache server virtual hosts not workingApache Web Server Configuration to install Owncloud 8.2.2 on Ubuntu 14.04Redirecting url to custom directoryHow to disable non-SSL on Apache on only the host without disabling in virtual hosts?installing a wildcard Certificate on a subdomain running on ubuntuApache2 HTTP Ubuntu Won't Restart






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









1


















System



Linux hosek 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


Issue



How should I configure multiple virtual hosts with a single configuration file in Apache using ssl with redirecting?



What is needed and not needed in my configuration below? Is possible for example set Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
to begin of file only? For all vhosts?



Is possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.



Example of my vhosts.



no-ssl.conffile.



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.thehatmakers.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.obrazduse.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>


ssl.conf file.



<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>

<VirtualHost *:443>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
DocumentRoot /var/www/html/obrazduse
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.



Update



If not possible to do with 1 VirtualHost, what about this configuration? Is any shorter way to do this? Is possible to use Redirect for ssl? As I have commented for *:443 configuration? Can I use Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
outside VirtualHost configuration? And what about google, is it ok with this redirecting? I am using 1 certificate for all domains, is it ok?



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
Redirect / https://www.thehatmakers.cz
</VirtualHost>

<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
#Redirect / https://www.thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ https://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.










share|improve this question






















  • 2





    Possible duplicate of When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt? Also: Redirect people after SSL is set up

    – pa4080
    Sep 20 at 7:27












  • @pa4080 Hi, this is not duplicate, because there are no ServerAlias options, and there is not answered if I can use both 80 and 443 in 1 VirtualHost configuration.

    – genderbee
    Sep 20 at 7:53






  • 1





    Hi, @genderbee. If you have an alias used within HTTPS/SSL virtual host you need to issue certificates for the both domain names: sudo letsencrypt --apache .... -d www.example.com -d example.com - they will be placed in the same certificate file. You can place the definitions for the VH on port 80 and for the VH on port 443 in one file, but there is no way to configure one virtual host to listen on two ports.

    – pa4080
    Sep 20 at 8:02












  • @pa4080 Thanks. And what about Redirect instead Rewrite in ssl config? See my update please. Thanks.

    – genderbee
    Sep 20 at 11:32












  • Hi, @genderbee, I've created more structured answer.

    – pa4080
    Sep 20 at 12:10

















1


















System



Linux hosek 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


Issue



How should I configure multiple virtual hosts with a single configuration file in Apache using ssl with redirecting?



What is needed and not needed in my configuration below? Is possible for example set Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
to begin of file only? For all vhosts?



Is possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.



Example of my vhosts.



no-ssl.conffile.



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.thehatmakers.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.obrazduse.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>


ssl.conf file.



<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>

<VirtualHost *:443>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
DocumentRoot /var/www/html/obrazduse
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.



Update



If not possible to do with 1 VirtualHost, what about this configuration? Is any shorter way to do this? Is possible to use Redirect for ssl? As I have commented for *:443 configuration? Can I use Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
outside VirtualHost configuration? And what about google, is it ok with this redirecting? I am using 1 certificate for all domains, is it ok?



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
Redirect / https://www.thehatmakers.cz
</VirtualHost>

<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
#Redirect / https://www.thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ https://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.










share|improve this question






















  • 2





    Possible duplicate of When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt? Also: Redirect people after SSL is set up

    – pa4080
    Sep 20 at 7:27












  • @pa4080 Hi, this is not duplicate, because there are no ServerAlias options, and there is not answered if I can use both 80 and 443 in 1 VirtualHost configuration.

    – genderbee
    Sep 20 at 7:53






  • 1





    Hi, @genderbee. If you have an alias used within HTTPS/SSL virtual host you need to issue certificates for the both domain names: sudo letsencrypt --apache .... -d www.example.com -d example.com - they will be placed in the same certificate file. You can place the definitions for the VH on port 80 and for the VH on port 443 in one file, but there is no way to configure one virtual host to listen on two ports.

    – pa4080
    Sep 20 at 8:02












  • @pa4080 Thanks. And what about Redirect instead Rewrite in ssl config? See my update please. Thanks.

    – genderbee
    Sep 20 at 11:32












  • Hi, @genderbee, I've created more structured answer.

    – pa4080
    Sep 20 at 12:10













1













1









1








System



Linux hosek 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


Issue



How should I configure multiple virtual hosts with a single configuration file in Apache using ssl with redirecting?



What is needed and not needed in my configuration below? Is possible for example set Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
to begin of file only? For all vhosts?



Is possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.



Example of my vhosts.



no-ssl.conffile.



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.thehatmakers.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.obrazduse.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>


ssl.conf file.



<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>

<VirtualHost *:443>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
DocumentRoot /var/www/html/obrazduse
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.



Update



If not possible to do with 1 VirtualHost, what about this configuration? Is any shorter way to do this? Is possible to use Redirect for ssl? As I have commented for *:443 configuration? Can I use Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
outside VirtualHost configuration? And what about google, is it ok with this redirecting? I am using 1 certificate for all domains, is it ok?



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
Redirect / https://www.thehatmakers.cz
</VirtualHost>

<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
#Redirect / https://www.thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ https://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.










share|improve this question
















System



Linux hosek 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


Issue



How should I configure multiple virtual hosts with a single configuration file in Apache using ssl with redirecting?



What is needed and not needed in my configuration below? Is possible for example set Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
to begin of file only? For all vhosts?



Is possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.



Example of my vhosts.



no-ssl.conffile.



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.thehatmakers.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
RewriteCond %SERVER_NAME =www.obrazduse.cz
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>


ssl.conf file.



<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ http://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>

<VirtualHost *:443>
ServerName www.obrazduse.cz
ServerAlias obrazduse.cz
RewriteCond %HTTP_HOST ^(obrazduse.cz) [NC]
RewriteRule ^(.*)$ http://www.obrazduse.cz$1 [R=301,L]
DocumentRoot /var/www/html/obrazduse
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.



Update



If not possible to do with 1 VirtualHost, what about this configuration? Is any shorter way to do this? Is possible to use Redirect for ssl? As I have commented for *:443 configuration? Can I use Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
outside VirtualHost configuration? And what about google, is it ok with this redirecting? I am using 1 certificate for all domains, is it ok?



<VirtualHost *:80>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
Redirect / https://www.thehatmakers.cz
</VirtualHost>

<VirtualHost *:443>
ServerName www.thehatmakers.cz
ServerAlias thehatmakers.cz
#Redirect / https://www.thehatmakers.cz
RewriteCond %HTTP_HOST ^(thehatmakers.cz) [NC]
RewriteRule ^(.*)$ https://www.thehatmakers.cz$1 [R=301,L]
DocumentRoot /var/www/html/thehatmakers
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


Thanks.







apache2 ssl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 20 at 17:57









Fabby

30.7k19 gold badges73 silver badges175 bronze badges




30.7k19 gold badges73 silver badges175 bronze badges










asked Sep 20 at 7:04









genderbeegenderbee

5248 bronze badges




5248 bronze badges










  • 2





    Possible duplicate of When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt? Also: Redirect people after SSL is set up

    – pa4080
    Sep 20 at 7:27












  • @pa4080 Hi, this is not duplicate, because there are no ServerAlias options, and there is not answered if I can use both 80 and 443 in 1 VirtualHost configuration.

    – genderbee
    Sep 20 at 7:53






  • 1





    Hi, @genderbee. If you have an alias used within HTTPS/SSL virtual host you need to issue certificates for the both domain names: sudo letsencrypt --apache .... -d www.example.com -d example.com - they will be placed in the same certificate file. You can place the definitions for the VH on port 80 and for the VH on port 443 in one file, but there is no way to configure one virtual host to listen on two ports.

    – pa4080
    Sep 20 at 8:02












  • @pa4080 Thanks. And what about Redirect instead Rewrite in ssl config? See my update please. Thanks.

    – genderbee
    Sep 20 at 11:32












  • Hi, @genderbee, I've created more structured answer.

    – pa4080
    Sep 20 at 12:10












  • 2





    Possible duplicate of When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt? Also: Redirect people after SSL is set up

    – pa4080
    Sep 20 at 7:27












  • @pa4080 Hi, this is not duplicate, because there are no ServerAlias options, and there is not answered if I can use both 80 and 443 in 1 VirtualHost configuration.

    – genderbee
    Sep 20 at 7:53






  • 1





    Hi, @genderbee. If you have an alias used within HTTPS/SSL virtual host you need to issue certificates for the both domain names: sudo letsencrypt --apache .... -d www.example.com -d example.com - they will be placed in the same certificate file. You can place the definitions for the VH on port 80 and for the VH on port 443 in one file, but there is no way to configure one virtual host to listen on two ports.

    – pa4080
    Sep 20 at 8:02












  • @pa4080 Thanks. And what about Redirect instead Rewrite in ssl config? See my update please. Thanks.

    – genderbee
    Sep 20 at 11:32












  • Hi, @genderbee, I've created more structured answer.

    – pa4080
    Sep 20 at 12:10







2




2





Possible duplicate of When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt? Also: Redirect people after SSL is set up

– pa4080
Sep 20 at 7:27






Possible duplicate of When does Ubuntu 16.04 use /etc/apache2/ssl/apache.crt? Also: Redirect people after SSL is set up

– pa4080
Sep 20 at 7:27














@pa4080 Hi, this is not duplicate, because there are no ServerAlias options, and there is not answered if I can use both 80 and 443 in 1 VirtualHost configuration.

– genderbee
Sep 20 at 7:53





@pa4080 Hi, this is not duplicate, because there are no ServerAlias options, and there is not answered if I can use both 80 and 443 in 1 VirtualHost configuration.

– genderbee
Sep 20 at 7:53




1




1





Hi, @genderbee. If you have an alias used within HTTPS/SSL virtual host you need to issue certificates for the both domain names: sudo letsencrypt --apache .... -d www.example.com -d example.com - they will be placed in the same certificate file. You can place the definitions for the VH on port 80 and for the VH on port 443 in one file, but there is no way to configure one virtual host to listen on two ports.

– pa4080
Sep 20 at 8:02






Hi, @genderbee. If you have an alias used within HTTPS/SSL virtual host you need to issue certificates for the both domain names: sudo letsencrypt --apache .... -d www.example.com -d example.com - they will be placed in the same certificate file. You can place the definitions for the VH on port 80 and for the VH on port 443 in one file, but there is no way to configure one virtual host to listen on two ports.

– pa4080
Sep 20 at 8:02














@pa4080 Thanks. And what about Redirect instead Rewrite in ssl config? See my update please. Thanks.

– genderbee
Sep 20 at 11:32






@pa4080 Thanks. And what about Redirect instead Rewrite in ssl config? See my update please. Thanks.

– genderbee
Sep 20 at 11:32














Hi, @genderbee, I've created more structured answer.

– pa4080
Sep 20 at 12:10





Hi, @genderbee, I've created more structured answer.

– pa4080
Sep 20 at 12:10










1 Answer
1






active

oldest

votes


















1



















In addition to the proposed duplication here are few specific to this question answers:




How do I setup HTTPS virtual host with ServerAlias in use.




If you are using ServerAlias directive within HTTPS/SSL virtual host you need to issue certificates for all domain names. By using letsencrypt you will need to add few -d options:



sudo letsencrypt --apache .... -d www.example.com -d example.com


All certificates will be placed in the same certificate file.




Is it possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.




You can place the definitions for all VirtualHosts in one file, thus it will be easy to enable and disable all of them together. But there is no way to configure one VirtualHost to listen on two ports.




What about Redirect instead Rewrite in ssl config?




According to the Apache2's documentation for such cases it is better to use the Redirect directive instead of Rewrite rules. Note, you need to create two separate VirtualHosts, if you want to redirect https://example.com to https://www.example.com . All related VirtualHosts can use the same certificate file, generated in the way described above.



Each virtual host will be responsible for a different ServerName, for example: ServerName example.com for the first, respectively ServerName www.example.com for the second, etc. Note the ServerAlias directive must be removed.



If everything works as it is expected, you can keep using Rewrite rules - this is subject of your decision. If you are using Redirect directive, do not miss the slash at the end of the target domain name! Here is an example for HTTPS VirtualHost that uses Redirect directive.



<VirtualHost *:443>
ServerName thehatmakers.cz
Redirect permanent "/" "https://www.thehatmakers.cz/"

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


  • At all, you do not need anything other for this VH.


  • The keyword permanent will instructs the client's browser to do this redirection automatically next time:




    • Redirect == HTTP 300


    • Redirect permanent == HTTP 301






share|improve this answer



























  • Hi, thanks. Then shortest and best configuration of this is as I wrote in update of my question, because there is only one redirect for all domains.

    – genderbee
    Sep 20 at 12:17











  • @genderbee, yes your updated example looks good. You just need one additional slash / at the end of Redirect / https://www.thehatmakers.cz >> Redirect / https://www.thehatmakers.cz/.

    – pa4080
    Sep 20 at 12:19











  • It works without / at the end too. ;)

    – genderbee
    Sep 20 at 12:21











  • @genderbee, yes it works when you are using http://example.com, but when there is any URI, like http://example.com/something it is highly possible to get redirection to https://example.comsomething ... when you are doing such tests use a new incognito window or different browser, or be sure your browser's cache is flushed.

    – pa4080
    Sep 20 at 12:24












  • Thanks for info.

    – genderbee
    Sep 20 at 12:33












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1175409%2fhow-should-i-configure-multiple-virtual-hosts-with-a-single-configuration-file-i%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown


























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1



















In addition to the proposed duplication here are few specific to this question answers:




How do I setup HTTPS virtual host with ServerAlias in use.




If you are using ServerAlias directive within HTTPS/SSL virtual host you need to issue certificates for all domain names. By using letsencrypt you will need to add few -d options:



sudo letsencrypt --apache .... -d www.example.com -d example.com


All certificates will be placed in the same certificate file.




Is it possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.




You can place the definitions for all VirtualHosts in one file, thus it will be easy to enable and disable all of them together. But there is no way to configure one VirtualHost to listen on two ports.




What about Redirect instead Rewrite in ssl config?




According to the Apache2's documentation for such cases it is better to use the Redirect directive instead of Rewrite rules. Note, you need to create two separate VirtualHosts, if you want to redirect https://example.com to https://www.example.com . All related VirtualHosts can use the same certificate file, generated in the way described above.



Each virtual host will be responsible for a different ServerName, for example: ServerName example.com for the first, respectively ServerName www.example.com for the second, etc. Note the ServerAlias directive must be removed.



If everything works as it is expected, you can keep using Rewrite rules - this is subject of your decision. If you are using Redirect directive, do not miss the slash at the end of the target domain name! Here is an example for HTTPS VirtualHost that uses Redirect directive.



<VirtualHost *:443>
ServerName thehatmakers.cz
Redirect permanent "/" "https://www.thehatmakers.cz/"

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


  • At all, you do not need anything other for this VH.


  • The keyword permanent will instructs the client's browser to do this redirection automatically next time:




    • Redirect == HTTP 300


    • Redirect permanent == HTTP 301






share|improve this answer



























  • Hi, thanks. Then shortest and best configuration of this is as I wrote in update of my question, because there is only one redirect for all domains.

    – genderbee
    Sep 20 at 12:17











  • @genderbee, yes your updated example looks good. You just need one additional slash / at the end of Redirect / https://www.thehatmakers.cz >> Redirect / https://www.thehatmakers.cz/.

    – pa4080
    Sep 20 at 12:19











  • It works without / at the end too. ;)

    – genderbee
    Sep 20 at 12:21











  • @genderbee, yes it works when you are using http://example.com, but when there is any URI, like http://example.com/something it is highly possible to get redirection to https://example.comsomething ... when you are doing such tests use a new incognito window or different browser, or be sure your browser's cache is flushed.

    – pa4080
    Sep 20 at 12:24












  • Thanks for info.

    – genderbee
    Sep 20 at 12:33















1



















In addition to the proposed duplication here are few specific to this question answers:




How do I setup HTTPS virtual host with ServerAlias in use.




If you are using ServerAlias directive within HTTPS/SSL virtual host you need to issue certificates for all domain names. By using letsencrypt you will need to add few -d options:



sudo letsencrypt --apache .... -d www.example.com -d example.com


All certificates will be placed in the same certificate file.




Is it possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.




You can place the definitions for all VirtualHosts in one file, thus it will be easy to enable and disable all of them together. But there is no way to configure one VirtualHost to listen on two ports.




What about Redirect instead Rewrite in ssl config?




According to the Apache2's documentation for such cases it is better to use the Redirect directive instead of Rewrite rules. Note, you need to create two separate VirtualHosts, if you want to redirect https://example.com to https://www.example.com . All related VirtualHosts can use the same certificate file, generated in the way described above.



Each virtual host will be responsible for a different ServerName, for example: ServerName example.com for the first, respectively ServerName www.example.com for the second, etc. Note the ServerAlias directive must be removed.



If everything works as it is expected, you can keep using Rewrite rules - this is subject of your decision. If you are using Redirect directive, do not miss the slash at the end of the target domain name! Here is an example for HTTPS VirtualHost that uses Redirect directive.



<VirtualHost *:443>
ServerName thehatmakers.cz
Redirect permanent "/" "https://www.thehatmakers.cz/"

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


  • At all, you do not need anything other for this VH.


  • The keyword permanent will instructs the client's browser to do this redirection automatically next time:




    • Redirect == HTTP 300


    • Redirect permanent == HTTP 301






share|improve this answer



























  • Hi, thanks. Then shortest and best configuration of this is as I wrote in update of my question, because there is only one redirect for all domains.

    – genderbee
    Sep 20 at 12:17











  • @genderbee, yes your updated example looks good. You just need one additional slash / at the end of Redirect / https://www.thehatmakers.cz >> Redirect / https://www.thehatmakers.cz/.

    – pa4080
    Sep 20 at 12:19











  • It works without / at the end too. ;)

    – genderbee
    Sep 20 at 12:21











  • @genderbee, yes it works when you are using http://example.com, but when there is any URI, like http://example.com/something it is highly possible to get redirection to https://example.comsomething ... when you are doing such tests use a new incognito window or different browser, or be sure your browser's cache is flushed.

    – pa4080
    Sep 20 at 12:24












  • Thanks for info.

    – genderbee
    Sep 20 at 12:33













1















1











1









In addition to the proposed duplication here are few specific to this question answers:




How do I setup HTTPS virtual host with ServerAlias in use.




If you are using ServerAlias directive within HTTPS/SSL virtual host you need to issue certificates for all domain names. By using letsencrypt you will need to add few -d options:



sudo letsencrypt --apache .... -d www.example.com -d example.com


All certificates will be placed in the same certificate file.




Is it possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.




You can place the definitions for all VirtualHosts in one file, thus it will be easy to enable and disable all of them together. But there is no way to configure one VirtualHost to listen on two ports.




What about Redirect instead Rewrite in ssl config?




According to the Apache2's documentation for such cases it is better to use the Redirect directive instead of Rewrite rules. Note, you need to create two separate VirtualHosts, if you want to redirect https://example.com to https://www.example.com . All related VirtualHosts can use the same certificate file, generated in the way described above.



Each virtual host will be responsible for a different ServerName, for example: ServerName example.com for the first, respectively ServerName www.example.com for the second, etc. Note the ServerAlias directive must be removed.



If everything works as it is expected, you can keep using Rewrite rules - this is subject of your decision. If you are using Redirect directive, do not miss the slash at the end of the target domain name! Here is an example for HTTPS VirtualHost that uses Redirect directive.



<VirtualHost *:443>
ServerName thehatmakers.cz
Redirect permanent "/" "https://www.thehatmakers.cz/"

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


  • At all, you do not need anything other for this VH.


  • The keyword permanent will instructs the client's browser to do this redirection automatically next time:




    • Redirect == HTTP 300


    • Redirect permanent == HTTP 301






share|improve this answer
















In addition to the proposed duplication here are few specific to this question answers:




How do I setup HTTPS virtual host with ServerAlias in use.




If you are using ServerAlias directive within HTTPS/SSL virtual host you need to issue certificates for all domain names. By using letsencrypt you will need to add few -d options:



sudo letsencrypt --apache .... -d www.example.com -d example.com


All certificates will be placed in the same certificate file.




Is it possible to make whole configuration to one file, especially one VirtualHost? I have 2 files now, one for 80, second for 443.




You can place the definitions for all VirtualHosts in one file, thus it will be easy to enable and disable all of them together. But there is no way to configure one VirtualHost to listen on two ports.




What about Redirect instead Rewrite in ssl config?




According to the Apache2's documentation for such cases it is better to use the Redirect directive instead of Rewrite rules. Note, you need to create two separate VirtualHosts, if you want to redirect https://example.com to https://www.example.com . All related VirtualHosts can use the same certificate file, generated in the way described above.



Each virtual host will be responsible for a different ServerName, for example: ServerName example.com for the first, respectively ServerName www.example.com for the second, etc. Note the ServerAlias directive must be removed.



If everything works as it is expected, you can keep using Rewrite rules - this is subject of your decision. If you are using Redirect directive, do not miss the slash at the end of the target domain name! Here is an example for HTTPS VirtualHost that uses Redirect directive.



<VirtualHost *:443>
ServerName thehatmakers.cz
Redirect permanent "/" "https://www.thehatmakers.cz/"

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hosek/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hosek/privkey.pem
</VirtualHost>


  • At all, you do not need anything other for this VH.


  • The keyword permanent will instructs the client's browser to do this redirection automatically next time:




    • Redirect == HTTP 300


    • Redirect permanent == HTTP 301







share|improve this answer















share|improve this answer




share|improve this answer








edited Sep 20 at 12:27

























answered Sep 20 at 12:10









pa4080pa4080

19.6k7 gold badges44 silver badges90 bronze badges




19.6k7 gold badges44 silver badges90 bronze badges















  • Hi, thanks. Then shortest and best configuration of this is as I wrote in update of my question, because there is only one redirect for all domains.

    – genderbee
    Sep 20 at 12:17











  • @genderbee, yes your updated example looks good. You just need one additional slash / at the end of Redirect / https://www.thehatmakers.cz >> Redirect / https://www.thehatmakers.cz/.

    – pa4080
    Sep 20 at 12:19











  • It works without / at the end too. ;)

    – genderbee
    Sep 20 at 12:21











  • @genderbee, yes it works when you are using http://example.com, but when there is any URI, like http://example.com/something it is highly possible to get redirection to https://example.comsomething ... when you are doing such tests use a new incognito window or different browser, or be sure your browser's cache is flushed.

    – pa4080
    Sep 20 at 12:24












  • Thanks for info.

    – genderbee
    Sep 20 at 12:33

















  • Hi, thanks. Then shortest and best configuration of this is as I wrote in update of my question, because there is only one redirect for all domains.

    – genderbee
    Sep 20 at 12:17











  • @genderbee, yes your updated example looks good. You just need one additional slash / at the end of Redirect / https://www.thehatmakers.cz >> Redirect / https://www.thehatmakers.cz/.

    – pa4080
    Sep 20 at 12:19











  • It works without / at the end too. ;)

    – genderbee
    Sep 20 at 12:21











  • @genderbee, yes it works when you are using http://example.com, but when there is any URI, like http://example.com/something it is highly possible to get redirection to https://example.comsomething ... when you are doing such tests use a new incognito window or different browser, or be sure your browser's cache is flushed.

    – pa4080
    Sep 20 at 12:24












  • Thanks for info.

    – genderbee
    Sep 20 at 12:33
















Hi, thanks. Then shortest and best configuration of this is as I wrote in update of my question, because there is only one redirect for all domains.

– genderbee
Sep 20 at 12:17





Hi, thanks. Then shortest and best configuration of this is as I wrote in update of my question, because there is only one redirect for all domains.

– genderbee
Sep 20 at 12:17













@genderbee, yes your updated example looks good. You just need one additional slash / at the end of Redirect / https://www.thehatmakers.cz >> Redirect / https://www.thehatmakers.cz/.

– pa4080
Sep 20 at 12:19





@genderbee, yes your updated example looks good. You just need one additional slash / at the end of Redirect / https://www.thehatmakers.cz >> Redirect / https://www.thehatmakers.cz/.

– pa4080
Sep 20 at 12:19













It works without / at the end too. ;)

– genderbee
Sep 20 at 12:21





It works without / at the end too. ;)

– genderbee
Sep 20 at 12:21













@genderbee, yes it works when you are using http://example.com, but when there is any URI, like http://example.com/something it is highly possible to get redirection to https://example.comsomething ... when you are doing such tests use a new incognito window or different browser, or be sure your browser's cache is flushed.

– pa4080
Sep 20 at 12:24






@genderbee, yes it works when you are using http://example.com, but when there is any URI, like http://example.com/something it is highly possible to get redirection to https://example.comsomething ... when you are doing such tests use a new incognito window or different browser, or be sure your browser's cache is flushed.

– pa4080
Sep 20 at 12:24














Thanks for info.

– genderbee
Sep 20 at 12:33





Thanks for info.

– genderbee
Sep 20 at 12:33


















draft saved

draft discarded















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1175409%2fhow-should-i-configure-multiple-virtual-hosts-with-a-single-configuration-file-i%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown









Popular posts from this blog

Tamil (spriik) Luke uk diar | Nawigatjuun

Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?