Virtualhosts not working, defaulting to html folder - virtualhost

I can't get virtualhosts to work, the server environment is RHEL
whenever I navigate to test.com it defaults to the index.html page in /www/html/ instead of the virtual server document root /var/www/test.com/public_html
below is an excerpt from the httpd.conf file:
NameVirtualHost *:80
IncludeOptional "/etc/httpd/sites-enabled/*.conf"
in /etc/httpd/sites-enabled/test.com.conf :
<VirtualHost *:80>
ServerName www.test.com
ServerAlias test.com www.test.com
DocumentRoot /var/www/test.com/public_html
</VirtualHost>
When I run httpd -S
...
port 80 namevhost www.test.com (/etc/httpd/sites-enabled/test.com.conf: 1)
alias test.com
alias www.test.com
port 80 namevhost default-http (/etc/httpd/conf.d/25-default-http.conf: 6)
...
I'm pretty new at this, any help appreciated thanks. I've also modified the hosts file on the client to point test.com to the server

When testing this on a browser it was defaulting to https which listens on port 443. I changed the listening port from 80 to 443: VirtualHost *:443 and it resolved. Alternatively I could also use http://www.test.com to view the page.

Related

One Apache virtual host resolves to index of/, while the others resolve correctly

I'm having an issues trying to resolve a third virtual host. The third virtual host always resolves to index of/.
Localhost and eshop.lh both correctly resolve their own individual index files.
UPDATE 1 I've added another test vHost, this also does not resolve correctly and serves index of/. Removing eshop and localhost does not change this behaviour.
UPDATE 2
Changed loglevel config to debug.
The errors i'm getting is no matching ServerName but it seems to be looking in SSL 433 VHost configurations. The names and paths are correct, no typos.
[ssl:debug] [pid 14388:tid 1924] ssl_engine_kernel.c(2364): [client 127.0.0.1:54023] AH02044: No matching SSL virtual host for servername engine.lh found (using default/first virtual host)
It then defaults the connection to (server www.example.com:443) which is the first configures (default) SSL VHost in the httpd-ssl.conf file.
As a test, i spoofed the ServerName for eshop.lh to see if it would also serve me the SSL Vhost default, but it doesn't. It serves me localhost which is the first Vhost configuration for port 80.
Vhost configuration: Showing spoofed eshop.lh and including 433 config too, that i left out previously.
VirtualHost configuration:
*:80 is a NameVirtualHost
default server localhost (C:/xampp/apache/conf/extra/httpd-vhosts.conf:46)
port 80 namevhost localhost (C:/xampp/apache/conf/extra/httpd-vhosts.conf:46)
port 80 namevhost engine.lh (C:/xampp/apache/conf/extra/httpd-vhosts.conf:53)
port 80 namevhost test.lh (C:/xampp/apache/conf/extra/httpd-vhosts.conf:60)
port 80 namevhost eshot.lh (C:/xampp/apache/conf/extra/httpd-vhosts.conf:67)
*:443 www.example.com (C:/xampp/apache/conf/extra/httpd-ssl.conf:121)
UPDATE 3
Re-installed xampp and it appears to be working smoothly now.
My configuration:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/localhost"
ServerName localhost
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/eshop.lh/"
ServerName eshop.lh
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/engine.lh/"
ServerName engine.lh
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
127.0.0.1 localhost
::1 localhost
127.0.0.1 eshop.lh
127.0.0.1 engine.lh
The paths are correct on my machine.
It's engine.lh that won't resolve correctly. eshop.lh works fine.
The file inside the engine.lh directory are simply:
read.me
index.html
Calling httpd -t -D DUMP_VHOSTS produces:
*:80 is a NameVirtualHost
default server localhost (C:/xampp/apache/conf/extra/httpd-vhosts.conf:44)
port 80 namevhost localhost (C:/xampp/apache/conf/extra/httpd-vhosts.conf:44)
port 80 namevhost eshop.lh (C:/xampp/apache/conf/extra/httpd-vhosts.conf:52)
port 80 namevhost engine.lh (C:/xampp/apache/conf/extra/httpd-vhosts.conf:60)
I restart apache with: hpptd -k restart or via the control panel.
In the apache docs: Name-based Virtual Host support, it gives this example to serve up different vhosts:
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com
DocumentRoot "/www/domain"
</VirtualHost>
<VirtualHost *:80>
ServerName other.example.com
DocumentRoot "/www/otherdomain"
</VirtualHost>

first VirtualHost must be localhost in httpd-vhosts.conf

Context: fresh wampserver 3.x install (windows10)
port 80 was used by microsoft iis so i change the port using wampserver tool (right click on the icon). Wampserver manage itself to change the port with 8080.
at this moment, httpd-vhosts.conf content is
# Virtual Hosts
#
<VirtualHost *:8080>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
and hosts content is:
#
127.0.0.1 localhost:8080
::1 localhost:8080
Purpose: create virtualhost for my project like http://myproject.localdev instead of http://localhost:8080/myproject/public/
what's going bad ?
by using wampserver link to create virtualhost, i got the error message below
first VirtualHost must be localhost in c:/wamp64/bin/apache/apache2.4.33/conf/extra/httpd-vhosts.conf
I used 8080 port too and had the same problem. What I've done - in httpd-vhosts.conf I added localhost with port 80 anyway, so I had both port 80 and port 8080:
<VirtualHost *:80>
ServerName localhost
....
<VirtualHost *:8080>
ServerName localhost
After that I opened localhost:8080 - there was a warning "Port used for the VirtualHost is not an Apache Listen port". Newertheless I clicked "Add a Virtual Host". The new host was added, then I restarted DNS (WAMP - Tools - Restart DNS).
After all you can delete from httpd-vhosts.conf localhost:80

Xampp Apache Virtual Hosts Not Redirecting

I'm using the Xampp tutorial to set up virtual hosts. My httpd-vhosts.conf looks like this...
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/www/mysite/public_html"
ServerName mysite.com
</VirtualHost>
My hosts entry looks like this..
127.0.0.1 mysite.com
The hosts part is working because mysite.com lands me on the Apache dashboard (mysite.com/dashboard).
I have the Apache server on 8080, and can browse to my site manually with http://127.0.0.1/www/mysite/public_html/
I've tried the virtual hosts config with 80 and 8080.
How can I get it to land on my site?
Edit: On my console (checking syntax) # httpd.exe -t Syntax OK

Apache 404 with specific port

I have a LAMP server and I have to use a port other than 80.
I set "Listen 3689" and I didn't remove "Listen 80".
When I use the port 80 everything works fine but when I try the other one I got 404.
Any ideas?
you should add a virtual host with the port you want
usually there is
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com
# Other directives here
</VirtualHost>
Now you need to add
<VirtualHost *:3689>
DocumentRoot /www/example1
ServerName www.example.com
# Other directives here
</VirtualHost>

Map phpMyAdmin to a port on CentOS and Apache

I was wondering how I would go about setting up the virtual hosts so that I just have to enter www.mydomain.com:9090 to go to phpmyadmin. This is how I have my vhosts set up right now in httpd.conf:
<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerName mydomain.com
ServerAlias www.mydomain.com
</VirtualHost>
<VirtualHost *:9090>
DocumentRoot /usr/share/phpMyAdmin/
ServerName mydomain.com
ServerAlias www.mydomain.com
</VirtualHost>
This does not seem to be working.
Have you tried adding... Listen 9090 to your config?
Add the new Virtual host in /etc/httpd/conf.d/localhost.conf and then edit httpd.conf in /etc/httpd/ to listen to new port. Restart httpd and then opened the port in IPtables. Apply the new rules.