Apache: forbidden on virtual host - apache

I've
/var/www/app.mydomain.com
This contain only on index.html with
<h1>I want it works ... please</h1>
This is my /etc/apache2/sites-enabled/app-mydomain-com.conf
<VirtualHost *:80>
ServerName app.mydomain.com
ServerAdmin info#mydomain.it
DocumentRoot /var/www/app.mydomain.com
CustomLog ${APACHE_LOG_DIR}/vhosts/app-mydomain-com/access.log vhost_combined
ErrorLog ${APACHE_LOG_DIR}/vhosts/app-mydomain-com/error.log
</VirtualHost>
When I open browser at app.mydomain.com I got a forbidden from apache
In the error.log (the main error.log, NOT the one specific of my vhost) I got
Cannot serve directory /var/www/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,
index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
I totally have no idea of what does it mean in my case
I tried to add
DirectoryIndex index.html
But nothing changes (after a restart of apache2, of course)
I verified that site was enabled
a2ensite app-mydomain-com
Site app-mydomain-com already enabled

At the end, the problem was only a missing ServerAlias directive.

Related

Apache conf setup to serve subdomain site alongside OwnCloud deploy

I have deployed OwnCloud 8 on a Ubuntu 14.04 instance to the domain box.example.com. I would like to host some static html on the same VM and have apache point project.example.com to it at /var/www/html.
In apache the file /etc/apache2/conf-available/owncloud.conf was created by OwnCloud containing:
#I changed the first line as follows
##Alias /owncloud "/var/www/owncloud/" # commented out
Alias / "/var/www/owncloud/"
<Directory "/var/www/owncloud">
Options +FollowSymLinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/owncloud
SetEnv HTTP_HOME /var/www/owncloud
</Directory>
How can I add a new subdomain VM in apache so that I'll have two working sites: box.example.com (OwnCloud instance) and project.example.com (static html). So far with everything I have tried project loads the OwnCloud front-end and does not open the static html.
Do I need to touch /etc/hosts?
I will update with examples of things I am trying and outcomes.
You can add both virtualhost in the same file (after the first ) directive or create another file in /etc/apache2/sites-available/ . You can start from the existing default file and adapt the servername and directory where your "project" is, and any other directive as needed.
Beware, if you run Apache2.4, the files should be named anyname.conf, for instance box.example.com.conf
And don't forgot to reload your apache server after having enabled the site.
You also need to set-up your DNS, in a zone file, for both box.example.com and project.example.com to point to the IP of your server.
You could create virtual host config files like /etc/apache/sites-available/01-owncloud.
<VirtualHost *:80>
ServerName box.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/owncloud
<Directory /var/www/owncloud/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/owncloud-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/owncloud-access.log combined
Redirect 301 /.well-known/carddav /remote.php/carddav
Redirect 301 /.well-known/caldav /remote.php/caldav
</VirtualHost>
Then enable it with a2ensite 01-owncloud.
Don't forget to set NameVirtualHost *:80 somewhere in a conf. I used /etc/apache2/ports.conf.

404 Not Found in incorrect Apache configuration

I have a problem that apache configuration. Here my virtual host setting.
<VirtualHost *:80>
ServerName orocrm.75cl.sg
DirectoryIndex app.php
DocumentRoot /var/www/html/oro/web
<Directory /var/www/html/oro/web>
# enable the .htaccess rewrites
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
But, when I access to other menus, http://orocrm.75cl.sg/oro/web/app.php/ is always shown in front of the my targeted menu. So, it was shown 404 page. e.g http://orocrm.75cl.sg/oro/web/app.php/magento/cart/. It should be like that http://orocrm.75cl.sg/app.php/magento/cart/
May I know how do I fix this issue.
I recall that some versions of Apache come with a pre-configured vhost to point to the welcome.conf and such.
So I would suggest commenting the welcome.conf which is at /etc/httpd or on some distros /etc/apache2 and in those same directories find and remove any installation virtual hosts.
After that you should be free of conflicts as the pre defined virtualhost is like follows:
<VirtualHost *:80>
DocumentRoot "/var/www/welcome"
And that is all I can remember from last time looking at the file.
Enjoy

Apache won't start with added VirtualHost, but gives no error in error log

I am using EasyPHP (version 16.1.1) for Apache server (installed version 2.4.18 x86). I need to add a new VirtualHost, so now the whole VirtualHost section of httpd.conf looks like this:
# VIRTUAL HOSTS
## Virtualhost localweb
<VirtualHost 127.0.0.1>
DocumentRoot "C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www"
ServerName 127.0.0.1
<Directory "C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www">
Options FollowSymLinks Indexes ExecCGI
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:8080>
UseCanonicalName Off
ServerAdmin marekbuchtela#gmail.com
ServerName posis
ServerAlias posis.tovarna
VirtualDocumentRoot "C:\Users\marek\is\tovarna\public"
</VirtualHost>
The first one is the default one made by EasyPHP, the second one is added by me. However in this setup, the Apache won't start. When I remove the second VirtualHost, everything works fine, but with it, it just won't start at all. I have checked the error log and there is no output at all.
Any ideas why is this happening/how to fix it?
Thanks
Switch VirtualDocumentRoot "C:\Users\marek\is\tovarna\public"for DocumentRoot "C:\Users\marek\is\tovarna\public"
If by any chance you keep getting the error, show error_log output
There is another instance other than the answer given by ezra-s as to why EasyPHP server won't start and the Apache error log is empty.
When declaring paths in the vhosts file, it is important that the directories referenced in those paths exist. If you provide the following VirtualHost information, for example:
<VirtualHost *:80>
DocumentRoot "D:/MyApp/public_html"
ServerName myapp.local
ErrorLog "D:/MyApp/logs/error.log"
CustomLog "D:/MyApp/logs/apache.log" common
</VirtualHost>
...but you don't have a D: drive, or the directories D:/MyApp/ and D:/MyApp/logs/ don't exist, then you'll get a "silent fail" in Apache when starting the HTTP server from the EasyPHP console.

CentOS Apache VirtualHost default

I have set up some virtal host to distinguish between my subdomains (/etc/httpd/conf.d/*.conf).
This was working on my old server (Debian 7). But now if I browse the root page I get the first defined VirtualHost displayed.
Also if I am browsing an undefined subdomain I get the first VirtualHost config displayed.
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName sub1.example.com
ServerAlias sub1.example.com
DocumentRoot /home/sub/sub_sub1/www
ServerAdmin Admin
CustomLog /home/sub/sub_sub1/logs/access.log combined
ErrorLog /home/sub/sub_sub1/logs/error.log
LogLevel warn
<Directory /home/sub/sub_sub1/www>
Require all granted
</Directory>
</VirtualHost>
The first defined VirtualHost will serve all the requests that don't get handled by the other ones. You can create a default VirtualHost that handles those requests. To make sure this VirtualHost is the first one, you should name its config-file something like "000-default.conf".
This might also help you: VirtualHost Examples

Return files only by strict path

I have a strange behavior of apache. I have file test.php in virtual server root and it's opens by url: example.com/test.php, but if I try to open this url example.com/test.php/noexists.php I also see content of example.com/test.php file.
File noexists.php dosen't exists on server, but server doesn't return 404 error. How to get 404 error for non existing files?
Apache 2.2, virtual server config:
<VirtualHost *:80>
ServerAdmin info#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/example.com.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/example.com.log combined
</VirtualHost>
" assume the location /test/ points to a directory that contains only
the single file here.html. Then requests for /test/here.html/more
and /test/nothere.html/more both collect /more as PATH_INFO "
[source]
That is the default behaviour. However you can change it by using this in your apache config files.
AcceptPathInfo Off