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

Is Fairphone violating the GPL with its newest Fairphone 3?

Which FIDE rule forbids pressing the clock before taking captured pieces off the board?

Creating an affinity-matrix between protein and RNA sequences

What did Rex Kramer mean by routing the plane in Lake Michigan?

A story in which God (the Christian god) is replaced

Adding "dot com" to the end of a sentence?

Why would anyone choose not use the lowlatency kernel?

GIMP using command line

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

In C#, is there a way to enforce behavior coupling in interface methods or is the fact that I am trying to do that a design smell?

How do you preserve fresh ginger?

Queuable Apex logic in Constructor or Execute Method

Chess Tournaments without Studying Theory?

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

Am I allowed to have a creature have 0 toughness, but still assign combat damage?

Two voices for a solo singer written in a sheet music

Total length of a set with the same projections as a square

How many cows would you need to drop on Mars to successfully terraform it?

Is it possible to trap yourself in the Nether?

Are there indications of a loss of past historical records in Star Trek universe?

How can I plot the two functions below with same color for each value of k?

Which Grows Faster: Factorial or Double Exponentiation

Storing info in JWT payload

How many flight hours do the first retiring A380s have?



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.4k7 gold badges43 silver badges90 bronze badges




19.4k7 gold badges43 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?

Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?