1

I have CentOS 8 I installed LAMP, Varnish, etc.

I setup hosts

/etc/hosts

ip site1.com www.site1.com ip site2.com www.site2.com

I setup Apache like this:

/etc/httpd.conf to include sites-enabled/

I have sites-enabled and sites-available with two configurations, site1.com.conf and site2.com.conf

Here what I included in etc/httpd/conf/httpd.conf

Include conf.modules.d/*.conf

and

IncludeOptional sites-enabled/*.conf

Still it is not working. Any idea how to fix this?

What i put in site1.com.conf example:

<VirtualHost *:8080>
    ServerName site1.com
    ServerAlias www.site1.com
    DocumentRoot /var/www/site1.com/html
    ErrorLog /var/www/site1.com/html/log/error.log
    CustomLog /var/www/site1.com/html/log/requests.log combined
</VirtualHost>

I manage to get this to work now but the https versions are not working Can you help guide me how to fix the https versions ? Thanks

Edit:. I fixed. Problem was IncludeOptional conf.d/*.conf was not in httpd.conf

Wed
  • 15
  • 9
  • What do you mean by "not working" exactly? Does literally "nothing" happen? _Something_ must happen... does it not resolve, do you get an error? – MrWhite Jan 29 '20 at 18:02
  • I manage to get site2.com to work problem is when i put http://ip_adress i want him to go to site1.com which is hosted external I try with Redirects but nop working – Wed Jan 29 '20 at 18:04
  • Why are you using port 8080 while referring to https sites without a port specified? https assumes port 443. Also, you need sslcertificate related lines lines and a "SSLEngine on" directive per virtualhost. – davidgo Jan 29 '20 at 18:27
  • I made the ssl certificates and changed in ssl.conf where exacty i should put sslengine on also ? – Wed Jan 29 '20 at 18:37

1 Answers1

1

Place the following in your httpd.conf then restart the service.

NameVirtualHost *:8080

<VirtualHost *:8080>
     ServerName site1.com
     ServerAlias www.site1.com
     DocumentRoot /var/www/site1
</VirtualHost>

<VirtualHost *:8080>
     ServerName site2.com
     ServerAlias www.site2.com
     DocumentRoot /var/www/site2
</VirtualHost>

Reference

slightly_toasted
  • 804
  • 5
  • 14
  • i put and restart but nothing should i delete all the httpd.conf extra files i put this data NameVirtualHost right after Include conf.modules.d/*.conf in http.conf should i delete rest modify ? – Wed Jan 29 '20 at 17:41
  • @Wed reset your configs to default, then add the `NameVirtualHost` and `VirtualHost` segments. – slightly_toasted Jan 29 '20 at 18:04
  • i tried that and yum reinstall apache but httpd.conf remain the same – Wed Jan 29 '20 at 18:10
  • @Wed run `yum remove apache` and make sure the config files are gone, if not then manually delete them. Then install apache again. Unfortunately, unlike `apt`, `yum` does not have a `purge` feature. – slightly_toasted Jan 29 '20 at 18:14
  • ok but how I get https://host_ip to redirect to external site and my site www.site2.com to /var/www/site2.com/html ? – Wed Jan 29 '20 at 18:20
  • You create a new new `VirtualHost` entry where the `ServerName` is your IP address and use the `Redirect` options to send clients to the specified external site. You can find out more about this by googling `VirtualHost permanent redirect`. – slightly_toasted Jan 29 '20 at 18:31
  • the https versions don't work how i fix that ? i made the ssl certificates but what to do ? – Wed Jan 29 '20 at 18:49
  • @Wed You will have to enable some SSL specific options for it to work. Please use google before asking all these follow up questions. You can easily find how to do this by googling `apache virtualhost ssl config`. – slightly_toasted Jan 29 '20 at 19:25
  • @MrWhite It's a very hacky way to reset the configs but based on OPs apparent knowledge about webservers I figured it's the easiest way to reset. – slightly_toasted Jan 29 '20 at 19:27
  • ok and how i get the ssl versions of this site work but https://ip and https://site2.com ? – Wed Jan 29 '20 at 19:33
  • @Wed refer to my last comment – slightly_toasted Jan 29 '20 at 19:38
  • i fixed nevermind i fixed is there a problem now @MrWhite that I yum reinstall httpd ? I managed to fix my issues but worry about the yum reinstall httpd any problem that may cause ? – Wed Jan 29 '20 at 20:20