Virtual Hosts Apache on Centos

Issues related to applications and software problems and general support
ogautier
Posts: 12
Joined: 2019/11/12 15:33:02

Virtual Hosts Apache on Centos

Post by ogautier » 2019/11/12 16:49:03

I'm trying to configure an Apache Web server. I have two sites www.reposteria.com and www.littlebrothers.com, and a DNS server pointing to this Apache Web server with http://desarrollolinux.smartienda.cl/.
I need to use diferent directories for each sites

http://desarrollolinux.smartienda.cl/reposteria and http://desarrollolinux.smartienda.cl/littlebrothers.

The commands used to configure this sites are:

mkdir -p /var/www/reposteria.com/public_html
mkdir -p /var/www/littlebrothers.com/public_html
chown -R apache:apache /var/www/reposteria.com/public_html
chown -R apache:apache /var/www/littlebrothers.com/public_html
chmod -R 755 /var/www
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled

nano /var/www/reposteria.com/public_html/index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Reposteria</title>
</head>
<body>
<h1>Virtual OK Reposteria.com</h1>
</body>
</html>

cp /var/www/reposteria.com/public_html/index.html /var/www/littlebrothers.com/public_html/index.html

nano /var/www/littlebrothers.com/public_html/index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Little</title>
</head>
<body>
<h1>Virtual OK Littlebrothers.com</h1>
</body>
</html>

nano /etc/httpd/conf/httpd.conf
IncludeOptional sites-enabled/*.conf

nano /etc/httpd/sites-available/reposteria.com.conf

<VirtualHost *:80>
ServerName www.reposteria.com
ServerAlias reposteria.com
DocumentRoot /var/www
</VirtualHost>

cp /etc/httpd/sites-available/reposteria.com.conf /etc/httpd/sites-available/littlebrothers.com.conf

nano /etc/httpd/sites-available/littlebrothers.com.conf

<VirtualHost *:80>
ServerName www.littlebrothers.com
ServerAlias littlebrothers.com
DocumentRoot /var/www/
</VirtualHost>

ln -s /etc/httpd/sites-available/reposteria.com.conf /etc/httpd/sites-enabled/reposteria.com.conf
ln -s /etc/httpd/sites-available/littlebrothers.com.conf /etc/httpd/sites-enabled/littlebrothers.com.conf

apachectl restart

nano etc/hosts
APACHE IP ADDRESS www.reposteria.com
APACHE IP ADDRESS www.ittlebrothers.com

apachectl restart

When I surf the Web using http://desarrollolinux.smartienda.cl/
I can see Virtual OK Littlebrothers.com, but if i use Virtual OK Littlebrothers.com/littlebrothers or Virtual OK Littlebrothers.com/reposteria I get this error:

Not Found

The requested URL /reposteria/ was not found on this server.

Does somebody can help me please?

Thanks!

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Virtual Hosts Apache on Centos

Post by TrevorH » 2019/11/12 17:38:26

DocumentRoot /var/www
That's the same for both sites and should be different. That looks wrong for both of them.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

BShT
Posts: 584
Joined: 2019/10/09 12:31:40

Re: Virtual Hosts Apache on Centos

Post by BShT » 2019/11/12 17:38:55

set DocumentRoot to /var/www/reposteria.com/public_html and /var/www/littlebrothers.com/public_html

ogautier
Posts: 12
Joined: 2019/11/12 15:33:02

Re: Virtual Hosts Apache on Centos

Post by ogautier » 2019/11/12 18:03:46

Thanks for the answers!

I have modified httpd.conf and add

DocumentRoot "/var/www/reposteria.com/public_html/"
DocumentRoot "/var/www/littlebrothers.com/public_html/"

After that I have restarted httpd service, and surf to http://desarrollolinux.smartienda.cl/reposteria/ but it does no work, I got the same answer from the server

Not Found

The requested URL /reposteria/ was not found on this server.

Do you have any other suggestions?

Regards!

BShT
Posts: 584
Joined: 2019/10/09 12:31:40

Re: Virtual Hosts Apache on Centos

Post by BShT » 2019/11/12 18:45:28

try to apachectl configtest and see if it is ok

ogautier
Posts: 12
Joined: 2019/11/12 15:33:02

Re: Virtual Hosts Apache on Centos

Post by ogautier » 2019/11/12 21:13:04

Thanks!!

The syntax is ok....Just reboot the server and it works fine.

Now if I surf www.littlebrothers.com or www.reposteria.com both sites response.

I have a couple of questions, what if I want to surf like:

http://desarrollolinux.smartienda.cl/reposteria or http://desarrollolinux.smartienda.cl/littlebrothers. What should I do? Should I point DNS Server to www.littlebrothers.com and www.reposteria.com?

How can I create the following structure?

www.littlebrothers.com/payment

where payment is another directory to run index.html or index.php.

Regards!

ogautier
Posts: 12
Joined: 2019/11/12 15:33:02

404 Error

Post by ogautier » 2019/11/13 13:19:53

I need to run a .html file from www.reposteria.com/payment, but when a try to surf to that address I got this 404 Error Not Found The requested URL /payment/ was not found on this server.

The DocumentRoot directive is:
DocumentRoot "/var/www/reposteria.com/public_html/payment"

The sites-available has a reposteria.com.conf whit this configuration:

<VirtualHost *:80>
#ServerAdmin webmaster@reposteria.com
ServerName www.reposteria.com
ServerAlias reposteria.com
DocumentRoot /var/www/reposteria.com/public_html/payment
ErrorLog /var/www/reposteria.com/error.log
CustomLog /var/www/reposteria.com/access.log combined
</Virtualhost>

Does anybody knows what shoul I do?
Thanks!

tunk
Posts: 1205
Joined: 2017/02/22 15:08:17

Re: 404 Error

Post by tunk » 2019/11/13 13:30:53

It could be wrong selinux settings for /var/www/reposteria.com (+subdirectories):
ls -lZ /var/www/reposteria.com

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Virtual Hosts Apache on Centos

Post by TrevorH » 2019/11/13 14:00:44

Let's keep all discussion about this in one thread rather than raising new ones all the time...
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

ogautier
Posts: 12
Joined: 2019/11/12 15:33:02

Re: Virtual Hosts Apache on Centos

Post by ogautier » 2019/11/13 15:40:37

This is the security context of each one. I disable Selinux to make a prove but the server response is the same 404 Not Found The requested URL /payment/ was not found on this server.

ls -lZ /var/www/reposteria.com/
total 12
-rwxr-xr-x 1 root root ? 4733 Nov 13 15:09 access.log
-rwxr-xr-x 1 root root ? 1220 Nov 13 12:38 error.log
drwxr-xr-x 4 apache apache ? 53 Nov 13 15:18 public_html

ls -lZ /var/www/reposteria.com/public_html/
total 4
-rwxr-xr-x 1 root root ? 165 Nov 12 17:14 index.html
drwxr-xr-x 2 root root ? 24 Nov 13 15:22 payment
drwxr-xr-x 2 root root ? 24 Nov 13 13:07 webpay

s -lZ /var/www/reposteria.com/public_html/payment/
total 4
-rwxr-xr-x 1 root root ? 14 Nov 13 15:22 index.html

Post Reply