(Apache) Forbidden 403 when accessing subdomain - apache

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 ....

Related

How apache2 can deny connections to a domain which is not hosted

I am hosting website iplocation.io on a cloud server. I found a domain https://chrissloey.com/index.php which opens my website within it.
Now from what I understand, chrissloey.com has pointed it A record to my server ip and my apache2 server is not denying connection to it and allow's to open iplocation.io website content like its own.
I want apache2 to deny connections to any other domain and only allow my own domain to server content.
Attached is apache conf file for iplocation.io
<VirtualHost *:80>
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
ServerName iplocation.io
ServerAlias www.iplocation.io
ErrorLog ${APACHE_LOG_DIR}/apache-error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName iplocation.io
ServerAdmin email#email.com
DocumentRoot /var/www/public_html
SSLEngine on
SSLCertificateFile /path-to-csr
SSLCertificateKeyFile /path-to-key
SSLCertificateChainFile /path-to-ca
<Directory /var/www/public_html>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</IfModule
Looking at the two comments I think the combination makes most sense:
Configure httpd to respond with redirect (301) to all incoming requests. This could be done on the 'root' host.
Configure a virtualhost listening to your domain only, and this one would serve your real content only.
This will work unless the other site requests your content and then integrates it into their responses. But as you said someone else simply put up a DNS A record.

laravel 5.3: setup virtual host. Getting Apache 404 error

I want to setup a virtual host in my localhost, so I can access my Laravel app like this: demo.example.com. I have added a custom conf file: etc/apache2/sites-available/example.com.conf with the following contents:
<VirtualHost *:80>
ServerAdmin username#gmail.com
ServerName example.com
ServerAlias www.example.com
ServerAlias demo.example.com
ServerAlias www.demo.example.com
DocumentRoot /var/www/example/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example/public>
AllowOverride All
</Directory>
</VirtualHost>
Contents from /etc/hosts file:
127.0.0.1 localhost
127.0.1.1 username-pc
127.0.0.1 example.com
127.0.0.1 www.example.com
127.0.0.1 http://exaple.com
127.0.0.1 demo.example.com
With the above settings if I access the url demo.example.com it works. But if I try to access other routes like demo.example.com/login I get apache 404 error: The requested URL /login was not found on this server. How do I fix this?
Note that this is not laravel's NotFoundHttpException.
place this under your directory tag
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

httpd subdomain 404 error

I have a working site at on the Top level of a domain, I now want to add a subdomain on the same domain and the same server.
The files for this site are located in the public html folder (/var/www/html)
I have the following virtualhosts/directory config in httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin support.portal#somesite.com
DocumentRoot /var/www/html/joomla3
ServerName support.somesite.com
ErrorLog logs/support.somesite.com_error.log
CustomLog logs/support.somesite.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin support.portal#somesite.com
DocumentRoot /var/www/html/moodle
ServerName support.somesite.com/moodle
ErrorLog logs/moodle.error.log
CustomLog logs/moodle.access.log common
</VirtualHost>
<Directory "/var/www/html/moodle">
DirectoryIndex index.php
AcceptPathInfo on
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
No errors are reported on the start/restart of httpd
Nothing is reported in the httpd error log. The below entry is shown in the Access log so the request is reaching the webserver but appears to be not being handled properly by the webserver.
192.168.4.202 - - [05/Jan/2015:12:49:14 +0000] "GET /moodle HTTP/1.1" 404 290
I have configured something similar before but I can't figure out the problem here. I might have missed something obvious, Can you see where the problem is, Thanks?
I am running CentOS 6.5 for reference.

Subdomain returns cgi error

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.

localhost redirecting to path specified for sub domain

In cakephp, I want to redirect localhost to app2 and client1.localhost to app1.
Instead both are redirecting to app1.
my httpd-vhost is defined as:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "D:\wamp\www\cakephp\app2\webroot\
ServerName localhost
</VirtualHost>
<VirtualHost www.myhost>
DocumentRoot "D:\wamp\app1\webroot"
ServerName client1.localhost
ServerAlias client1.localhost
<Directory "D:\wamp\app1\webroot">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
At first glance there are a few weird things with your vhost config:
The first document root has no closing "
the virtualhost names should both be the same
your referring to the webroot, instead of the approot (there's also a .htacces in your approot)
I use CakePHP 2.x with wamp server with a configuration like this:
make sure the vhost file is uncommented in your apache configuration:
wamp/bin/apache/Apache[version]/conf/httpd.conf (or left click wamp->apache->httpd.conf)
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Try this in wamp/bin/apache/Apache[version]/conf/extra/httpd-vhosts.conf
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName client1.localhost
DocumentRoot "D:\wamp\app1"
<Directory "D:\wamp\app1">
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
<VirtualHost *:80>
ServerName dev.localhost
DocumentRoot "D:\wamp\www\cakephp\app2"
<Directory "D:\wamp\www\cakephp\app2">
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
and put this in your hosts file (C:\windows\system32\drivers\etc)
127.0.0.1 localhost
127.0.0.1 dev.localhost
127.0.0.1 client1.localhost
Do a wamp restart all services.
App2 will be available on both localhost and dev.localhost