Apache VirtualHost with SSL Not Found

10,823

Solved. The problem is ServerName at the head of httpd.conf. It should be removed if the main domain is defined as VirtualHost.

Share:
10,823

Related videos on Youtube

Ap Tsi
Author by

Ap Tsi

Software and Telecommunication Engineer. Love learning from anyone.

Updated on September 18, 2022

Comments

  • Ap Tsi
    Ap Tsi over 1 year

    I setup 3 virtual hosts on port 80. Everything is fine. Now I would setup the SSL version of these virtual hosts. All works except the main DocumentRoot.

    Listen 80 
    ServerName www.mydomain.com
    NameVirtualHost *:80
    NameVirtualHost *:443
    <VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /home/someone/www/work
        ServerName work.example.com
        <Directory /home/someone/www/work>
        Options +FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        </Directory>
    
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /home/someone/www
        ServerName www.example.com
        <Directory /home/someone/www>
        Options +FollowSymlinks
        AllowOverride All
        Order allow,deny
        allow from all
        </Directory>
    </VirtualHost>
    
    <VirtualHost *:443>
        ServerAdmin [email protected]
        DocumentRoot /home/someone/www/work
        ServerName work.example.com
        SSLEngine on
        SSLCertificateFile /home/someone/ssl-certs-keys/c1.crt
        SSLCertificateKeyFile /home/someone/ssl-certs-keys/c1.key
        SSLCertificateChainFile /home/someone/ssl-certs-keys/c1.i.crt
    
        <Directory /home/someone/www/work>
        Options +FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        </Directory>
    
    </VirtualHost>
    
    <VirtualHost *:443>
        ServerAdmin [email protected]
        DocumentRoot /home/someone/www
        ServerName www.example.com
        SSLEngine on
        SSLCertificateFile /home/someone/ssl-certs-keys/c1.crt
        SSLCertificateKeyFile /home/someone/ssl-certs-keys/c1.key
        SSLCertificateChainFile /home/someone/ssl-certs-keys/c1.i.crt
        <Directory /home/someone/www>
        Options +FollowSymlinks
        AllowOverride All
        Order allow,deny
        allow from all
        </Directory>
    </VirtualHost>
    

    Now, no problem if I connect to www.example.com, work.example.com, https://work.example.com. The only problem is that when I connect to https://www.example.com, I get The requested URL / was not found on this server".

    If I add somewhere in httpd.conf DocumentRoot /home/someone/www the pages there are loaded... Why, for 443, I have to add DocumentRoot, and why the VirtualHost for the main domain is not read.

    [EDIT]

    As for a comment, if I type httpd -S

    VirtualHost configuration:
    
    wildcard NameVirtualHosts and _default_ servers:
    *:443                  is a NameVirtualHost
             default server www.mydomain.com (/etc/httpd/conf.d/ssl.conf:74)
             port 443 namevhost www.mydomain.com (/etc/httpd/conf.d/ssl.conf:74)
             port 443 namevhost work.mydomain.com (/etc/httpd/conf/httpd.conf:1074)
    

    Why the default server points to ssl.conf and not httpd.conf?

    • Jenny D
      Jenny D almost 10 years
      What does your apache log say?
    • Ap Tsi
      Ap Tsi almost 10 years
      in ssl_error_log "File does not exist: /etc/httpd/htdocs"
    • Jenny D
      Jenny D almost 10 years
      There's something wrong with your config but I can't find it from what you've posted here. There might be a typo that's hidden by your obfuscation, for instance. You can try doing httpd -S to show the virtualhost settings and include them into the question.
  • Jenny D
    Jenny D almost 10 years
    I would use the name of the server instead, but that's largely a matter of taste. (For instance, my personal web server is called "sameen" which I use as the main ServerName, and has a virtual host with "www.example.com".)
  • Ap Tsi
    Ap Tsi almost 10 years
    Well, if I do not delete the ServerName outside the VirtualHost blocks, the problem arises.
  • fuero
    fuero over 7 years
    Nothing in this question mentions Let's Encrypt or trouble accessing said folders.