Help cleaning up my apache virtual hosts reddit / selfhosted ---------------------------------------------------------------------- DickCamera ยท 2023-12-29 15:53 Can anyone help me cleanup/understand my apache virtual hosts config? I'm an engineer, not an admin :) I host 2 different sites on my server DOMAIN_ONE.dev and DOMAIN_TWO.com Originally domain_two was only on port 80, but I recently got a cert for it so it's now on 443 as well. domain_one is .dev so it can only be on 443 domain1 has multiple subdomains (git, gallery, etc...) which I have properly configured via CF dns. Domain2 has no (real) subdomains, other than the possibility of someone typing in www.domain_two.com which I have a dns entry for and I want that to redirect appropriately. The subdomains on domain_one are correctly working, but I feel like I'm doing so in some sort of convoluted way. Is there anything I can clean up? Additionally, is there any vhost I can add to cover any invalid subdomains? Like if someone requests invalid.DOMAIN_ONE.dev, I would like them to get redirected to https://DOMAIN_ONE.dev. Can that also work for any http request? I apologize, what I have below was mostly trial and error and I find the apache configs a bit confusing as I'm not sure if I'm building overrides, cascading rules or what. # Primary entry for DOMAIN_ONE SSLEngine on ServerName DOMAIN_ONE.dev DocumentRoot /www/DOMAIN_ONE.dev ErrorLog /var/log/httpd/DOMAIN_ONE.dev.error.log CustomLog /var/log/httpd/DOMAIN_ONE.dev.access.log combined SSLCertificateFile "/etc/ssl/certs/DOMAIN_ONE.dev/fullchain.cer" SSLCertificateKeyFile "/etc/ssl/certs/DOMAIN_ONE.dev/DOMAIN_ONE.dev.key" Options Indexes FollowSymLinks AllowOverride All Require all granted # git subdomain ServerName git.DOMAIN_ONE.dev ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ CustomLog /var/log/httpd/git.DOMAIN_ONE.dev.access.log combined # gallery subdomain ServerName gallery.DOMAIN_ONE.dev DocumentRoot /www/sigal/_build CustomLog /var/log/httpd/gallery.DOMAIN_ONE.dev.access.log combined Options Indexes FollowSymLinks Require all granted # primary site for DOMAIN_TWO ServerName DOMAIN_TWO.com ServerAlias *.DOMAIN_TWO.com DocumentRoot /www/DOMAIN_TWO.com ErrorLog /var/log/httpd/DOMAIN_TWO.com.error.log CustomLog /var/log/httpd/DOMAIN_TWO.com.access.log combined SSLCertificateFile "/etc/ssl/certs/DOMAIN_TWO.com/fullchain.cer" SSLCertificateKeyFile "/etc/ssl/certs/DOMAIN_TWO.com/DOMAIN_TWO.com.key" Options Indexes FollowSymLinks AllowOverride All Require all granted # Map www.DOMAIN_TWO.com to primary? ServerName DOMAIN_TWO.com ServerAlias *.DOMAIN_TWO.com Redirect permanent / https://DOMAIN_TWO.com