Apache2 custom 404 Page won't load (.htaccess) - html

i want to create a custom errorpage for my small webserver which runs on apache2 on raspbian. But sadly the created page isn't loaded by a browser in case of an URL which can't be resolved ... the browser just prints the path to the created errorpage on the upper left-hand corner.
html of the custom page so far:
<!DOCTYPE html><html><head></head><body><p>Nooooot found ...</p></body></html>
html of the loaded page:
<html><head></head><body>sites/errorsites/404.html</bod></html>
My .htaccess-file, which is placed in /var/www/
Options -Indexes
ErrorDocument 404 sites/errorsites/404.html
Location of my errorsites-dir with custom errorsites: /var/www/sites/
(Of course I set "AllowOverride" in the default-file in /etc/apache2/sites-available to "all".)
Thanks for the help
Lukas
Edit:
default-file of apache:
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined

From the ErrorDocument docs:
URLs can begin with a slash (/) for local web-paths (relative to the
DocumentRoot), or be a full URL which the client can resolve.
Alternatively, a message can be provided to be displayed by the
browser.
sites/errorsites/404.html does not begin w/ a slash and so is treated as a message to be displayed. Changing it to /sites/errorsites/404.html should fix, if sites is relative to your DocumentRoot…

Related

What causes Apache to invoke an executable on the server?

I have an executable on the server that is suppose to be invoked by the browser but the browser downloads it instead as a binary file to the "Downloads" directory .
The index.html has:
<head>
<title></title>
<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=admin/launch?script=rhtemplate=login">
</head>
How does "launch" get started ?
ScriptAlias /admin/ "/opt/tms/lib/web/cgi-bin/"
<Directory "/opt/tms/lib/web/cgi-bin">
Options +ExecCGI
AllowOverride None
Options None
Order Allow,Deny
Allow from all
</Directory>
This use to work in httpd 2.0 ; we updated to 2.2
There are a couple of things that need to be set.
http://httpd.apache.org/docs/2.4/howto/cgi.html
you could put your executable in a ScriptAliased directory. default apache configs normally have /cgi-bin/ as a ScriptAlias. So if you move your script to there it should Just work.
ScriptAlias "/scripts/" "/usr/local/apache2/scripts/"
can be used to set up different directory, or to create one if your default doesn't include it.
Or if you want to allow execution outside of ScriptAlias directories, you can set Options +ExecCGI in the directory and then tell Apache what should be treated as a script.
Enable cgi execution in that directory.
<Directory "/usr/local/apache2/htdocs/admin">
Options +ExecCGI
</Directory>
Then you would need to tell Apache what extensions should be treated as cgi using a handler
AddHandler cgi-script .cgi .pl
so you would need to rename your script to something like launch.cgi
-- from new info --
<Directory "/opt/tms/lib/web/cgi-bin">
Options +ExecCGI
AllowOverride None
Options None
Order Allow,Deny
Allow from all
</Directory>
you have Options none and Options +ExecCGI in that stanza, remove the Options none, and see if that makes a difference..

Apache2- need multiple projects with same domain that use different path after domain name

I have 2 completely different projects I would like to host from the same domain name "mysimpledomainname.com" with ip address xx.xx.xxx.xx (not local)
The 2 projects are located at
Project 1) /var/www/html/project1
Project 2) /var/www/html/project2
I would like to have the 2 projects resolve like this
Project 1
mysimpledomainname.com
project 2
mysimpledomainname.com/project2
I DO NOT want to use subdomain names. This is for a project on my public server, not my local machine, so I don't think updating the host file will help me.
I already have the first project loading from mysimpledomainname.com (it's already working).
In the directory sites-available I have the conf file mysimpledomainname.com.conf with values:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot /var/www/html/project1
<Directory /var/www/html/project1/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I think I need to have 2 different conf files set up in order to do this, but after searching around I have not been able to find a solution.
Can anyone help me with this? Rather than giving a short answer can you post exactly what I would need for the 2 different conf files?
Thanks,
David
You can have only 1 VirtualHost directive as this is defined per FQDN and you want to use only mysimpledomainname.com.
Your config for Project1 is OK. You just need to make available another directory under path /project2. To do this, you need to use the Alias directive.
So your final config should be something like this (of course you can have separate Directory configurations for each subdir if you want):
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot /var/www/html/project1
Alias /project2 /var/www/html/project2
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Treating a subdirectory as a root directory for Apache

I cannot find a way to do what I want. I want to upload a project to my server at http://example.com/MyNewProject
In each of the web pages I include a file which does all of the imports for stylesheets, JavaScript etc. I don't want to provide the full path every time I just want to be able to do /MyStylesheet.css
My main websites document root is /var/www/html/example and my new projects directory is stored within /var/www/html/example/MyNewProject.
What I want is in my import when I do /MyStylesheet.css instead of going to my servers main web directory it will go to /var/www/html/example/MyNewProject in order to get the CSS.
I've tried adding the following to my Apache config file:
Alias /NewProjectTemplate "/var/www/html/example/NewProjectTemplate"
Alias /NewPRojectTemplate/ "/var/www/html/example/NewProjectTemplate"
<Directory "/var/www/html/example/NewProjectTemplate">
Options Indexes FollowSymLinks Includes
AllowOverride All
XBitHack On
Order allow,deny
Allow from all
</Directory>
This unfortunately hasn't worked so I've also tried adding the following to my virtualhosts file
<VirtualHost *:80>
DocumentRoot /var/www/html/example/NewProjectTemplate
ServerName example.com/NewProjectTemplate
</VirtualHost>
I've looked around on Google but cannot find anything specific, the only thing I've found is something to do with using the Rewrite engine but this seems a little too complicated and OTT for my needs.
Update
I've got a little further, although not a lot, I'm sure its not supposed to be this complicated.
Instead of using the virtual hosts, I'm now using an alias and below is what I've added to my httpd.conf file
DocumentRoot "/var/www/html"
Alias /NewTemp/ "/var/www/html/example/NewProjectTemplate/"
Alias /NewTemp "/var/www/html/example/NewProjectTemplate"
<Directory "/var/www/html/example/NewProjectTemplate/">
Options FollowSymLinks Includes
AllowOverride all
</Directory>
<Directory "/var/www/html/example/NewProjectTemplate">
Options FollowSymLinks Includes
AllowOverride all
</Directory>
In my HTML code in my SSI I am doing the following:
<!--#include file="includes/imports.html"-->
As you can see this is a relative path and Includes is inside the root of NewProjectTemplate. However, this is a template file so I want it to always to go to the root to find the file so it is guaranteed to work no matter how deep into the site it. For example if I change the line to the below I then get an error error processing directive
<!--#include file="/includes/imports.html"-->
So even though it works without the / but doesn't with the slash, if I don't include the slash so this import then works, the imports within the imports.html file work even though they do contain the leading slash so it always go to the root. Below is my HTML imports file
<link rel="stylesheet" type="text/css" href="/StyleSheet.css">
<link rel="stylesheet" type="text/css" href="/navigation/top-nav.css">
<link rel="stylesheet" type="text/css" href="/navigation/side-nav.css">
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script type="text/javascript" src="/scripts/menu.js"></script>
So just to clarify, if the #include file = includes/imports.html the SSI directive works and /StyleSheet.css is successfully imported even though it has the leading slash. If I add a / to the path of the SSI it then doesn't get imported.
But here is where it gets weirder.
If I then add another file to a subdirectory e.g. NewProjectTemplate/MySubDirectory and then add the SSI to be ../includes/imports.html it still doesn't work. Its like the #include file SSI directive expects the file to be in the same working directory.
So, have you tried like this in the virtual host?
<VirtualHost *:80>
ServerAdmin emailaddress#domain.com
DocumentRoot "/var/www/html/example/"
ServerName example.local
ServerAlias example.local
<Directory "/var/www/html/example/">
Options All Includes Indexes FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
Alias /NewProjectTemplate /var/www/html/example/NewProjectTemplate
<Directory "/var/www/html/example/NewProjectTemplate">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Hope it helps this time..
Just accidentally stumbled across this very old threat.
No need of host or alias if you just want a sub dir to be treated as root.
The way to do it is to amend the httpd.conf, there you will find
<Directory>
just update this line and add
<Directory "your/server/root/original_path/subpath">
# your options
</Directory>

Apache hangs with Django Application and Matplotlib

Very stuck here and I don't have a whole lot to go on. I had a django application up and running and I started playing around with graphing using NetworkX and Matplotlib to visualize some of the data for a poster. I then tried to use the site again and got the error:
'/var/www' is not a writable dir; you must set /var/www/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored
Which I resolved by chmod'ding the directory. The site's homepage then loads fine but when I try to load any other page that django renders apache just hangs. I set the log level to debug and tail'ed it but it's not showing any new requests or errors or anything, it just sorta hangs until the browser gives up. I then thought it must just be an error with something that I just did so I reverted back to a working version in my repo and am having the same problem. Django's test server is still running the site fine which is leading me to believe that it's a problem with apache (of the whole thing apache is the part I have the least experience with).
my httpd.conf looks like:
ServerName >> my server <<
TraceEnable off
AcceptFilter http none
AcceptFilter https none
EnableMMAP off
EnableSendfile off
<VirtualHost *:80>
ServerAdmin >> my email <<
ServerName >> my server <<
DocumentRoot /Web/public/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
WSGIScriptAlias / /home/$USER/$APP/$APP/wsgi.py
<Directory /Web/public/static>
Options -Indexes
</Directory>
Alias /static /Web/public/static
Alias /media /Web/public/media
ErrorLog /var/log/apache2/error.log
LogLevel debug
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Please let me know if you have any thoughts, or need any more info.
Thanks!
I had the same problem; Apache/Django would not work but manage.py runserver would work fine. I tried making the default directory readable, and I tried changing MPLCONFIGDIR with export MPLCONFIGDIR=/stuff/, but the only thing that worked was placing
import os
os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'
BEFORE importing matplotlib. Only one page uses MPL in my case, so placing this 'everywhere' was acceptable to me.
Taken from original solution by steko.

Apache2. How to work with <Location> and <Directory> together?

I'm trying to set specified configuration for location in my apache configuration.
But it isn't working for me.
<VirtualHost 127.0.0.1:80>
ServerName site.ru
DocumentRoot /storage/htdocs
<Directory />
Header add Dir 1
</Directory>
<Location ~ "api">
Header add Api 1
</Location>
</VirtualHost>
I need to extend my directory section with my api section.
But I can't see "Api: 1" in headers list.
What's wrong?
The path in the <Directory> directive must match your DocumentRoot. It's relative to the filesystem, not the document root.