Do I have to duplicate the Virtualhost directives for port 80 and 443?

后端 未结 6 1253
长发绾君心
长发绾君心 2021-01-30 05:19

I have a long and intricate list of directives, and I have to duplicate them into separate groups for ports 80 and 443 because I\'m using

6条回答
  •  礼貌的吻别
    2021-01-30 05:42

    Sorry to bump up an old post like this, but in order to help other Googlers out there I wanted to share how I dealt with it:

    I have a couple of vhosts on my localhost, say: localhost, foo.com, bar.com

    This being a localhost site on my laptop (macosx) I could get away with self-signed certificates and thus the ssl-part is the same for all the vhosts...

    What I did is this:

    I created the directory /etc/apache2/extra/vhosts/.

    I created a /etc/apache2/extra/vhosts/localhost.conf:

    ServerName localhost
    DocumentRoot "/www/localhost"
    
      Require all granted
    
    ErrorLog "/var/log/apache2/localhost.error_log"
    CustomLog "/var/log/apache2/localhost.access_log" common
    

    A /etc/apache2/extra/vhosts/foo.conf:

    ServerName foo.com
    DocumentRoot "/www/foo.com"
    
      Require all granted
    
    ErrorLog "/var/log/apache2/foo.com.error_log"
    CustomLog "/var/log/apache2/foo.com.access_log" common
    

    A /etc/apache2/extra/vhosts/bar.conf:

    ServerName bar.com
    DocumentRoot "/www/bar.com"
    
      Require all granted
    
    ErrorLog "/var/log/apache2/bar.com.error_log"
    CustomLog "/var/log/apache2/bar.com.access_log" common
    

    And finally a /etc/apache2/extra/vhosts/ssl.conf:

    SSLEngine on
    SSLCertificateFile "/etc/apache2/ssl/server.crt"
    SSLCertificateKeyFile "/etc/apache2/ssl/server.key"
    

    And in my /etc/apache2/extra/httpd-vhosts.conf:

    
      Include /etc/apache2/extra/vhosts/localhost.conf
    
    
      Include /etc/apache2/extra/vhosts/localhost.conf
      Include /etc/apache2/extra/vhosts/ssl.conf
    
    
    
      Include /etc/apache2/extra/vhosts/foo.conf
    
    
      Include /etc/apache2/extra/vhosts/foo.conf
      Include /etc/apache2/extra/vhosts/ssl.conf
    
    
    
      Include /etc/apache2/extra/vhosts/bar.conf
    
    
      Include /etc/apache2/extra/vhosts/bar.conf
      Include /etc/apache2/extra/vhosts/ssl.conf
    
    

提交回复
热议问题