Apache server -- multiple directories, different error logs - apache2

I have two directories in /var/www (say, /var/www/app1 and /var/www/app2) whose error logs I want sent to different files. Both are under the same domain, so I think that I can't put them under different virtual hosts. So, for example, I would access them as:
http://localhost/app1
http://localhost/app2
I came across this page:
Generate access logs for different subdirectories in Apache
whose solution works perfectly for the access logs. However, the "env" argument doesn't seem to work with the ErrorLog directive.
Before this "discovery", I was working on this, which seems wrong:
<VirtualHost *:80>
ServerAdmin ray#localhost
DocumentRoot /var/www/app1
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/app1/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/app1/access.log combined
</VirtualHost>
I'm somewhat lost about what I should be doing. That is, if there is some way to get ErrorLog to work or if I should keep trying with configuring a virtual host for each directory. Any help would be appreciated! Thank you!

Why do you set Directory options for / in the VirtualHost context? Use <Directory /var/www/app1> instead of <Directory />
Due to the Apache ErrorLog directive docs its context is server config, virtual host - which means that it's only possible to define ErrorLog for the whole server or for a VirtalHost, not for a Directory. So if you want to send different logs to different files, try to use SetEnvIf to set an Env variable. Depeding on the directory where you are, it should be something like SetEnvIf Request_URI ^\/a1\/ a1 and SetEnvIf Request_URI ^\/a2\/ !a1. Then write logs depending on the a1 environment variable.

Set custom ID for every Directory and you can separate logs by directories like this:
<Directory app1>
SetEnv app1
</Directory>
<Directory app2>
SetEnv app2
</Directory>
CustomLog ${APACHE_LOG_DIR}/site1.log combined env=app1
CustomLog ${APACHE_LOG_DIR}/site2.log combined env=app2

Finally I did it, first create internal subdomains per folder and with proxypass pass the subdomain content.
Enable apache mods:
a2enmod authz_core dir proxy proxy_http
/etc/hosts
127.0.0.1 localhost
127.0.0.1 a.localhost
127.0.0.1 b.localhost
/etc/apache2/sites-available/default.conf
<VirtualHost *:80>
ServerName localhost
ServerAdmin fake#mail.com
DocumentRoot "/dev/null"
ProxyPass /a http://a.localhost/
ProxyPassReverse /a http://a.localhost/
ProxyPass /b http://b.localhost/
ProxyPassReverse /b http://b.localhost/
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/default-error.log
CustomLog ${APACHE_LOG_DIR}/default-access.log combined
</VirtualHost>
/etc/apache2/sites-available/a.conf
<VirtualHost *:80>
ServerName a.localhost
ServerAdmin fake#mail.com
DocumentRoot "/Publikoa/a"
<Directory "/Publikoa/a">
DirectoryIndex index.html
Require all granted
</Directory>
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/a-error.log
CustomLog ${APACHE_LOG_DIR}/a-access.log combined
</VirtualHost>
/etc/apache2/sites-available/b.conf
<VirtualHost *:80>
ServerName b.localhost
ServerAdmin fake#mail.com
DocumentRoot "/Publikoa/b"
<Directory "Publikoa/b">
DirectoryIndex index.html
Require all granted
</Directory>
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/b-error.log
CustomLog ${APACHE_LOG_DIR}/b-access.log combined
</VirtualHost>
Enable sites:
a2ensite default a b
Restart apache:
/etc/init.d/apache2 restart

Related

Can't access index.php after modifying the 000-default.conf to suit dms setup

So I've been trying to install Seeddms. I just re-flashed the os on my current samba server and wanted to add this DMS to just make life easier. I've flowed the steps mentioned on this website (Install Guide for old Seeddms). I am aware that this is for the old version of Seeddms and have changed all the version related code.
Question is...
What haven't I done to allow access to the index.php page after modifying the 000-default.conf ?
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory />
Require all granted
</Directory>
Alias /seeddms “/home/www-data/seeddms50x/seeddms-5.0.8/“
<Directory "/home/www-data/seeddms50x/seeddms-5.0.8/">
DirectoryIndex index.php
AllowOverride All
Order deny,allow
Deny from all
Allow from all
</Directory>
</VirtualHost>
Located in -> "/etc/apache2/sites-enabled/"
I try and access the install page using the web address of
http://steve/seeddms/install
(**steve being the name of the samba server)
However, no luck.
Any Ideas ?

Apache2: 2 virtual hosts (domain & subdomain) / 1 IP - not working

I have this conf-file set-up:
Listen 80
<VirtualHost 0.0.0.0:80>
ServerAdmin webmaster#localhost
ServerName test.example.com
WSGIScriptAlias / /var/django/test/test/wsgi.py
#WSGIPythonPath /var/django/test
<Directory /var/django/test/test>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost 0.0.0.0:80>
ServerAdmin webmaster#localhost
ServerName www.example.com
ServerAlias *.example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Whenever I open www.example.com, test.example.com or example.com I always receive the standard apache website.
If I delete the second VirtualHost I get an access denied (since the permissions for the wsgi-file are note properly set).
But why can't I run 2 (or more) different VirtualHost of differnt subdomains?
Thanks!
Kev
PS.: I try to run a Django-Site on the subdomain test.example.com
I found the error.
In the second there was a "." instead of a "80".

VirtualHost on Apache2 gives no response

I'm trying to create a virtual host on apache2 but I am getting no response. I have tried serveral tutorials but nothing has helped. This is my file:
<VirtualHost *:80>
ServerName androidwebservice.com
DocumentRoot "/var/www/my_webservice/public"
LogLevel warn
ErrorLog /var/log/apache2/redmine_error.log
CustomLog /var/www/my_webservice/android_access.log combined
<Directory "/var/www/my_webservice/">
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
RailsEnv production
RailsBaseURI /my_webservice
PassengerResolveSymlinksInDocumentRoot on
</Directory>
</VirtualHost>
I have enabled it using the command sudo a2ensite androidbackend(this is the file name). The file is located in /etc/apache2/sites-available.
The ServerName has been declared in /etc/hosts:
127.0.1.1 androidwebservice.com
Are you visiting androidwebservice.com or www.androidwebservice.com
Because you have declared androidwebservice.com not www.androidwebservice.com
The basic (working) example is over here:
https://reformatcode.com

Apache2 is not wanting to be deleted

I am having trouble removing a VirtualHost, so I thought of just simply editing the /etc/apache2/sites-available/default file. It turns out that I am trying to add the original 'index.html' file, which I have in the /var/www/ directory. But it is not working because another VirtualHost has taken port 80 and I don't see my 'index.html' file listed there in the default file. I am super frustrated, so I am thinking of just doing a fresh install of the apache2 service. But even though I use this command to remove it:
sudo apt-get install --remove apache2 php5 libapache2-mod-php5
Even though I do this, it is not removed and I get this error at the end of the process:
Errors were encountered while processing:
libopenvnc-imgproc2.3
libavfilter2:armhf
libav-tools
ffmpeg
E: Sub-process /usr/bin/dpkg returned an error code (1)
Is there any way to do a fresh install of apache2 along with php5 and libapache2-mod-php5 as I had installed them when I first got my Pi? I am just lost, I have gone to a million forums and none have helped me.....
Here is the 'default' file text:
NameVirtualHost *:8091
NameVirtualHost *:80
NameVirtualHost *:443
This is what I tried doing, but it didn't work, it said the file couldn't be found!
<VirtualHost *:80>
DocumentRoot /var/www/remote_replay.php
ServerName 192.168.1.80
</VirtualHost>
This part below works fine, but I want it removed!!!!!
WSGIDaemonProcess web2py user=www-data group=www-data
<VirtualHost *:8091>
WSGIProcessGroup web2py
WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
WSGIPassAuthorization On
<Directory /home/www-data/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>
AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \
/home/www-data/web2py/applications/$1/static/$2
<Directory /home/www-data/web2py/applications/*/static/>
Options -Indexes
Order Allow,Deny
Allow from all
</Directory>
<Location /admin>
Deny from all
</Location>
<LocationMatch ^/([^/]+)/appadmin>
Deny from all
</LocationMatch>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/self_signed.cert
SSLCertificateKeyFile /etc/apache2/ssl/self_signed.key
WSGIProcessGroup web2py
WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
WSGIPassAuthorization On
<Directory /home/www-data/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>
AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \
/home/www-data/web2py/applications/$1/static/$2
<Directory /home/www-data/web2py/applications/*/static/>
Options -Indexes
ExpiresActive On
ExpiresDefault "access plus 1 hour"
Order Allow,Deny
Allow from all
</Directory>
CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>
There is a problem with your virtual host configuration, DocumentRoot must be a directory. If you want to serve a specific file, use DocumentIndex to specify the files to use in order of preference:
<VirtualHost *:80>
DocumentRoot /var/www/
DocumentIndex remote_replay.php index.php index.html index.htm
ServerName 192.168.1.80
</VirtualHost>

Apache2 serving multiple sites on one IP

I have two domains that point to the same IP, which is an Ubuntu VPS with apache2. I need to server both domains out of apache. I've read the config manual at http://httpd.apache.org/docs/2.0/vhosts/examples.html#purename and added the following two files:
1) webikenconsultants
<VirtualHost *:80>
ServerName www.webikenconsultants.com
DocumentRoot /var/www/coming_soon
<Directory /var/www/coming_soon>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
2) webikentrading
<VirtualHost *:80>
ServerName www.webikentrading.net
#WSGIScriptAlias / /opt/webikentrading/current/src/webikentrading/django.wsgi
DocumentRoot /var/www
<Directory /var/www >
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
As you can see, webikentrading is a Django project, but for the time being, just to get things working, I am serving it as a static site, until I figure out what's going on. The problem is that when I visit either domain, only the coming_soon content shows up, what am I doing wrong??
I figured out the problem. The vhost entry points to www.webikentrading.net however, the browser was using webikentrading.net so i added a separate entry for just webikentrading.net and all is fine
EDIT:
This is quite old, but I have a new and improved way of doing this now and I hope it can help someone else.
Use the mod_wsgi daemon directive which allows you to add the python path of your choice. Example config is:
<VirtualHost *:80>
ServerName qa.webiken.net
....
WSGIDaemonProcess qa.webiken.net processes=2 threads=15 python-path=/usr/local/pythonenv/QA-WEBIKEN-1/lib/python2.5/site-packages display-name=%{GROUP}
WSGIProcessGroup qa.webiken.net
</VirtualHost>
<VirtualHost *:80>
ServerName staging.webiken.net
....
WSGIDaemonProcess staging.webiken.net processes=2 threads=15 python-path=/usr/local/pythonenv/staging-WEBIKEN-1/lib/python2.5/site-packages display-name=%{GROUP}
WSGIProcessGroup staging.webiken.net
</VirtualHost>

Resources