LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Internal VM development web server running CentOS7 with multiple site directories in /var/www/html setup (https://www.linuxquestions.org/questions/linux-newbie-8/internal-vm-development-web-server-running-centos7-with-multiple-site-directories-in-var-www-html-setup-4175653959/)

witchkinkofangmar 05-15-2019 11:50 AM

Internal VM development web server running CentOS7 with multiple site directories in /var/www/html setup
 
I have an internal development vm server people will use to test their site’s code.

In the /var/www/html/ directory, there are about 15 site directories mounted from a SAN. None of this will be accessible externally.

How do you redirect to those directories on one server with one IP?

Should I create A records for all the internal sites so they have their own and attach a virtual nic for each one?

Or should I use .htaccess or httpd.conf to redirect somehow? New to this so any advice or links on how this is done is good. I’m not sure how to phrase searches and can’t find much on my own.

—thanks

smallpond 05-15-2019 11:59 AM

Apache can serve multiple sites from one IP using the hostname in the URL. In that case, the clients need to send a hostname in the URL, so you will need your local DNS to point all of the sites to one IP. If you want to do HTTPS its a little more work, because you need a properly configured certificate for each site.

https://opensource.com/article/18/3/...b-sites-apache

witchkinkofangmar 05-15-2019 12:18 PM

Nice, so I need to add a virtual host config for each site in httpd.conf it looks like.

<VirtualHost *:80>
DocumentRoot /var/www/html/site1
ServerName www.site1.org
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/html/site2
ServerName www.site2.org
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/html/site3
Servername www.site3.org

</VirtualHost>

witchkinkofangmar 05-15-2019 04:17 PM

This works great for sites on the server itself, but only the main directory at /var/www/html is available outside the server.

If I go to the other sites on a different machine on the same network, I can only access them if I update my /etc/hosts file

mysite.org works, which is actually the VMs name
mysite2.org doesn't except on VM
mysite3.org doesn't except on VM

Is there something that can be done without assigning different ports that users would have to attach to the name or updating the users hosts file? I'd like to avoid them having to add the port.
...
<VirtualHost *:81>
DocumentRoot /var/www/html/site2
ServerName site2.org:81
</VirtualHost>
...
mysite.org
mysite2.org:81
mysite3.org:82

scasey 05-15-2019 05:44 PM

This may not be the issue, but...if you define ServerName as www.site1.org apache won't know from just site.org.
Add a ServerAlias directive to the VirtualHost
Code:

ServerAlias site.org
No, you do not need to (and shouldn't) use multiple ports. We serve a couple hundred domains on port 80...but only by name, of course.

As smallpond said.
Quote:

you will need your local DNS to point all of the sites to one IP
Alternatively, you can match the domain name to IP address in the remote 'puter's /etc/hosts, which you say works.

You have to do something to point users to the IP address by name...either DNS or /etc/hosts.

witchkinkofangmar 05-16-2019 11:26 AM

I was able to add an A record on that IP to get site2 and site3 working. I did also add a ServerAlias for them.

I did this yesterday as well (not the server alias), and it didn't seem to work but after about 10-15 minutes, it did. I guess it just took a while to propagate and I wasn't patient enough.

Thanks for all the help!

scasey 05-16-2019 04:39 PM

Quote:

Originally Posted by witchkinkofangmar (Post 5995707)
I was able to add an A record on that IP to get site2 and site3 working. I did also add a ServerAlias for them.

I did this yesterday as well (not the server alias), and it didn't seem to work but after about 10-15 minutes, it did. I guess it just took a while to propagate and I wasn't patient enough.

Thanks for all the help!

Glad you got it working. You can mark your thread SOLVED using the thread tools, if you want.

Yes, it can take time for changes like that to propagate. I'm on Cox at home, and changes to DNS can take up to 30 minutes to be seen on my home desktops, although 5-10 minutes is the norm.


All times are GMT -5. The time now is 08:47 AM.