Subdomain returns cgi error - apache

I have created a virtual host with a subdomain, the subdomain's dns is pointed at the server. When I visit the subdomain I get the following error:
The requested URL "/cgi-sys/defaultwebpage.cgi" was not found on this server.
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
ServerAlias test.domain.com
ServerAdmin admin#domain.com
DocumentRoot /var/www/public/domain.com
<Directory "/var/www/public/domain.com">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /error.log
CustomLog /access.log combined
</VirtualHost>
I have tried using *.domain.com as well.
If I use a local host to point domain.com at the server it works as expected, but using localhost does not allow the subdomain to work in either case.

Turns out that my syntax is correct, chrome's dns caching had cached the bad page. Using firefox worked.

Related

Apache virtual host subdomains not working

I am using httpd-vhosts.conf,apache version 2.4.51 and Windows Server.
The subdomain is not working.
httpd-vhosts.conf:
NameVirtualHost *:80
#
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "e:/wamp64/www/mydomain.com"
<Directory "e:/wamp64/www/mydomain.com/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
#
<VirtualHost *:80>
ServerName subdomain.mydomain.com
ServerAlias subdomain.mydomain.com
DocumentRoot "e:/wamp64/www/mydomain.com/subdomain"
<Directory "e:/wamp64/www/mydomain.com/subdomain/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Both mydomain.com and www.mydomain.com works great!
But if i try using: http://subdomain.mydomain.com i always got the error:
Hmm. We’re having trouble finding that site.
We can’t connect to the server at subdomain.mydomain.com
If that address is correct, here are three other things you can try:
Try again later.
Check your network connection.
If you are connected but behind a firewall, check that Firefox has permission to access the Web.
hosts file is correct too:
127.0.0.1 mydomain.com
::1 mydomain.com
127.0.0.1 subdomain.mydomain.com
::1 subdomain.mydomain.com
P.S. I can access it directly from the host machine, but i can't on another device.
Why only the subdomain is not working, please?
What am i missing?
Thank you!!!
It seems to be more a DNS problem than a config problem on your serveur. Did you set any DNS for your subdomain ? Maybe you could find some help here :
https://www.godaddy.com/help/create-a-subdomain-4080

(Apache) Forbidden 403 when accessing subdomain

I want to set up the subdomain "shop" on my Apache 2.2 server on Windows/XAMPP and it redirects to "index.html" if I enter "shop.localhost" as the URL but once I try to connect via my domain "sv443.net" it redirects to my document root ("/index.html" instead of "/shop/index.html"). Connecting to "sv443.net/shop/" works fine though and even redirects to "index.html".
I'm using Cloudflare to handle the DNS stuff and added these records (I cut off the IP address part):
This is my httpd-vhosts.conf:
NameVirtualHost localhost:80
<VirtualHost localhost:80>
ServerName localhost
ServerAdmin sven.fehler#web.de
DocumentRoot "c:/users/sv443/desktop/mamp htdocs"
<Directory "c:/users/sv443/desktop/mamp htdocs">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost shop.localhost:80>
ServerName shop.localhost
ServerAdmin sven.fehler#web.de
DocumentRoot "c:/users/sv443/desktop/mamp htdocs/shop"
<Directory "c:/users/sv443/desktop/mamp htdocs/shop">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
And this is my hosts.dat:
(only comments)
2.205.169.73 sv443.net
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost shop.localhost
Also I added this .htaccess file to the shop directory to redirect to the index.html if a 403 or 404 is encountered - removing this file doesn't fix my problem:
ErrorDocument 403 /shop/index.html
ErrorDocument 404 /shop/index.html
If someone tries to connect I get this error message in the Apache error.log:
AH01630: client denied by server configuration: C:/Users/Sv443/Desktop/MAMP htdocs/shop/.html
Thanks for any help!
If you can get content by explicitly specifying "/index.html" but not with "/", you should add DirectoryIndex index.html in your configuration, after loading mod_dir. This will define the default file to look for when it is not specified.
For your VirtualHost:
<VirtualHost *:80>
ServerName localhost
ServerAlias www.example.com
ServerAlias example.com
LogLevel debug
CustomLog "logs/example_access_log" combined
ErrorLog "logs/example_error_log"
[... REST OF CONFIGURATION ...]
</VirtualHost>
<VirtualHost *:80>
ServerName shop.localhost
ServerAlias shop.example.com
LogLevel debug
CustomLog "logs/shop_access_log" combined
ErrorLog "logs/shop_error_log"
[... REST OF CONFIGURATION ...]
</VirtualHost>
Apache decides which VirtualHost to use for the request based on the domain in the request. If it does not find a match, it uses the first one in the file (here localhost). Therefore you are not pointing to your "shop" sub-domain, unless you specify it in the VirtualHost for it, via ServerAlias ....

Apache disable localhost redirection

i got a problem with apache conf with Laragon.
so the case is :
i got 2 subdomain
subdom1.mysite.com (DNS Record to IP 1.2.3.4)
subdom2.mysite.com (DNS Record to IP 1.2.3.4)
IP 1.2.3.4 is my VPS
everything went well, but i got a problem.
when i access 'localhost' from my VPS, it keeps redirecting to subdom1.mysite.com
and localhost/phpMyAdmin also redirected to subdom1.mysite.com/phpMyAdmin
here's my httpd.conf
Define APACHE_LOG_DIR "C:/mydir/logs"
Define APACHE_ROOT_WEB_DIR "C:/mydir/wwwroot"
ServerName localhost
DocumentRoot "C:/mydir/wwwroot"
<Directory "C:/mydir/wwwroot">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName subdom1.mysite.com
ServerAlias subdom1.mysite.com
DocumentRoot ${APACHE_ROOT_WEB_DIR}\subdom1.mysite.com
ErrorLog ${APACHE_LOG_DIR}/subdom1.mysite.com-error.log
CustomLog ${APACHE_LOG_DIR}/subdom1.mysite.com-access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName subdom2.mysite.com
ServerAlias subdom2.mysite.com
DocumentRoot ${APACHE_ROOT_WEB_DIR}\subdom2.mysite.com
ErrorLog ${APACHE_LOG_DIR}/subdom2.mysite.com-error.log
CustomLog ${APACHE_LOG_DIR}/subdom2.mysite.com-access.log combined
</VirtualHost>
my localhost keeps redirecting to first vHost. I've googled lot's of combination of directory, serverName etc. But no luck.
Your VirtualHosts are binding to all available interfaces. Because of how apache determines to which VHost should route a request, it's ending up in the first one defined.
You can either:
Bind your subdomains to the external ip only.
Create a VirtualHost for the main server using the loopback ip.
Create a VirtualHost with the _default_ address.

How do I hide the IP & port in my URL with Apache?

Some information:
If I go to mysite.com:9999 I get my site like 45.40.45.40:9999 .. and the 45.40.45.40 is the public ip of my router followed by the non-standard port used to connect my apache server on virtualbox on ubuntu.
I use dns redirect from namecheap.com in order to redirect mysite.com to my public_ip:used_port_to_connect_Apache so it wil be like so: 45.40.45.40:9999 in the url after I get connected.
My question is: how can I convert/returned the '45.40.45.40:9999' to the original domain name which is mysite.com only?
What do I need to do? Is this an Apache configuration setting somewhere? It is a Virtual Host on Apache server.
/etc/apache2/sites-available/mysite.com.conf:
Listen 9999
<VirtualHost *:9999>
<Directory /var/www/mysite.com/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerAdmin info#mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Apache VirtualHost not pointing to correct subdirectory

I am a newbie to apache and server setup. I am migrating several sites from GoDaddy to a DigitalOcean VPS droplet. I am moving my first site over (a Wordpress install) and am having some trouble with VirtualHost. Here is the configs:
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/html/domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Heres the thing, I have a www alias set up in the domain name records, and www.domain.com points correctly to the site, but domain.com points to the root var/www/html, not the subdirectory where the site is. I've searched for far too long, but every tutorial and forum seems to provide the same code I currently have configured. What am I doing wrong? I want to make sure it all works correctly before I take the next step of installing an SSL, but I am spinning my wheels at the moment.
The correct way to set up a virtual host is:
<VirtualHost *:80>
ServerAdmin admin#domain.com
DocumentRoot /path/to/the/directory
DirectoryIndex index.html index.php
ServerName domain.com
ServerAlias www.domain.com
ErrorLog ${APACHE_LOG_DIR}/domain.com.error.log
CustomLog ${APACHE_LOG_DIR}/domain.com.access.log combined
<Directory /path/to/the/directory>
Options -Indexes
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>