Apache conf VirtualHost ignored

1 answer

I'm running apache on a CentOS 7. I have 2 config files in /etc/httpd/conf.d :

  • A10-my_site_dev.conf
  • A10-my_site_test.conf

As they are similar, I show you only one of the files :

<VirtualHost *:443>     ErrorLog "logs/my_site_test.log"     SSLCertificateFile /etc/ssl/host/host.crt     SSLCertificateKeyFile /etc/ssl/host/host.key      Alias /my-site/test/static /var/www/my_site_test/static/     <Directory /var/www/my_site_test/static>         Require all granted     </Directory>      WSGIScriptAlias /my-site/test /var/www/my_site_test/app/wsgi.py     <Directory /var/www/my_site_test>         Require all granted     </Directory> </VirtualHost> 

Currently, VirtualHost in A10-my_site_test.conf is ignored. If I go to https://my-server.com/my-site/test, I've got a 404, but https://my-server.com/my-site/dev is working fine. If I remove A10-my_site_dev.conf and restart apache, https://my-server.com/my-site/test works. I understood that it takes only the first VirtualHost apache finds.

I have the feeling that VirtualHost in my ssl.conf is ignored too cause, if I move SSLCertificateFile and SSLCertificateKeyFile to ssl.conf, I have the following error :

enter image description here

I tried not to use VirtualHost, and everything works fine in that case. I think all VirtualHost are ignored except the first.

I've got the same problem with other ports (like 80).

Another point : I read that I should have a ServerName. But I have the same ServerName for all my environments. I tried to put something random such as "my_site_test" as ServerName, but I've got a 404.

How could I configure apache to make my 2 files work ?

All answers to this question, which has the identifier 58306595

The best answer:

This is not how VirtualHosts work. Especially with SSL.

So you have:

<VirtualHost *:443>     CONFIGURATION FOR DEV </VirtualHost>  <VirtualHost *:443>     CONFIGURATION FOR TEST </VirtualHost> 

The only difference between both VirtualHosts is the logs and directory? That will not work.

Apache can distinguish between VirtualHost sections based on:

  • IP associated to the domain
  • Port
  • ServerName (for non-SSL configurations)

The way you configured it right now, Apache cannot distinguish between both VirtualHosts. So it takes the first one it finds. That explains the mix up with certificates.

Ex of a working configuration

# www.example1.com == 1.1.1.1 # www.example2.com == 2.2.2.2  <VirtualHost 1.1.1.1:443>     ServerName www.example1.com      # SSL CONFIG     # LOGS CONFIG     # OTHER CONFIGURATION  </VirtualHost>  <VirtualHost 2.2.2.2:443>     ServerName www.example2.com      # SSL CONFIG     # LOGS CONFIG     # OTHER CONFIGURATION  </VirtualHost> 

Read the documentation (again?), it will do you good: https://httpd.apache.org/docs/2.4/vhosts/examples.html

There are posts on this site explaining the finer points of SSL VirtualHosts configuration (I even wrote some myself).

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data