lmrogers Posted July 8, 2021 Posted July 8, 2021 Afternoon, I'm setting up 2 different sites on a single Ubuntu 20 server. I have got the folders created and the permissions sorted. It started off being a server hosting a single development site which has a virtual host file which redirects all traffic to HTTPS. I then added another site to the server, again with a separate virtual host file again redirecting traffic to HTTPS. Enabled both sites, but the issue is that both URLs are routing to the same Document root folder of the new site despite the DocumentRoot folder being different in the virtual host file. Any one got any pointers on how to setup the virtual hosts or where I could be going wrong?
lmrogers Posted July 8, 2021 Author Posted July 8, 2021 If I have a basic VirtualHost file for the second server pointing at port 80 without any redirect everything works as expected. Is there a better way of doing this at all?
TechMonkey Posted July 8, 2021 Posted July 8, 2021 It has been a while since I played with VirtualHosts. Have you restarted the services after changing? I seem to remember Apache holding on quite tightly to the virtualHosts info. Are you able to post a sanitised version of your file?
jthompson Posted July 8, 2021 Posted July 8, 2021 I'm not an Apache expert at all, but have been fiddling with Apache and HTTPS a bit this week. I know that there are different ways of doing things so it will depend on what directives you're using in your VirtualHost definitions, and how your two sites are addressed (i.e. different domains, different subdomains of the same domain, or same domain with different paths).
lmrogers Posted July 8, 2021 Author Posted July 8, 2021 (edited) These are the 2 virtual host files I have created. Site 1 ServerName dev-site.org Redirect permanent / https://dev-site.org ServerAdmin [email protected] DocumentRoot /var/www/dev-site ErrorLog ${APACHE_LOG_DIR}/dev-site-error.log CustomLog ${APACHE_LOG_DIR}/dev-site-access.log combined SSLEngine on SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt SSLCertificateKeyFile /etc/apache2/certificate/apache.key Site 2 ServerName sub.domain.org Redirect permanent / https://sub.domain.org ServerAdmin [email protected] DocumentRoot /var/www/sub-site ErrorLog ${APACHE_LOG_DIR}/sub-site-error.log CustomLog ${APACHE_LOG_DIR}/sub-site-access.log combined SSLEngine on SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt SSLCertificateKeyFile /etc/apache2/certificate/apache.key I've restarted apache server after every change I made, tested in InPrivate and different browsers as well in case it was some cache issue. Edited July 8, 2021 by lmrogers
jthompson Posted July 8, 2021 Posted July 8, 2021 (edited) I think you're missing the ServerName directive in each of your *:443 blocks. It's probably then just serving the first one of those that matches whenever a request comes in on 443, regardless of the URL being requested. Edited July 8, 2021 by jthompson 1
lmrogers Posted July 8, 2021 Author Posted July 8, 2021 I think you're missing the ServerName directive in each of your *:443 blocks. It's probably then just serving the first one of those that matches whenever a request comes in on 443, regardless of the URL being requested. Yes! Thank you! Knew I would just be being a bit blind and stupid!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now