
|
View Full Version : Server wide 404 page?
Hi Everyone,
I am leaning towards leasing a dedicated server from DialTone next week. The plan is to only host my own domains on the server, at least in the beginning. Is there a way to have a server wide default 404 page, that loads whenever a document not found error occurs on any of the domains hosted on this server?
Thanks
~Marcus
brendan 09-29-2000, 09:01 PM Marcus,
I have a server that is going to be available next week, if you are interested in hearing more about it send me an email.
-Brendan
brendan@hostrocket.com
Please keep posts on topic and keep in mind the guidelines set out at http://www.webhostlink.com/announcement.php?forumid=1 Thank you.
cbaker17 09-29-2000, 09:26 PM Goodnews: yes there is
Bad News: Im not sure how, ill try to get one of our techs to look at your post and tell you how.
Matt Lightner 09-29-2000, 09:45 PM One way you could do it is by adding the following to your httpd.conf:
ErrorDocument 404 http://www.website.com/defaulterror.html
But you need to put this in each virtual host.
Matt
mlightner@site5.com
Félix C.Courtemanche 09-30-2000, 02:48 AM Originally posted by Site5-Matt
One way you could do it is by adding the following to your httpd.conf:
ErrorDocument 404 http://www.website.com/defaulterror.html
But you need to put this in each virtual host.
To do it server wide, you must have these lines (for the most common errors) in your httpd.conf or srm.conf file (usually found under /etc/httpd/conf/)
ErrorDocument 401 /path/to/401.html
ErrorDocument 403 /path/to/403.html
ErrorDocument 404 /path/to/404.html
ErrorDocument 500 /path/to/500.html
it can be .php .cgi, whatever. It is the same as putting it in a .htaccess file but affects everyone.
Matt Lightner 09-30-2000, 12:58 PM Yes.. but the thing about that is that they are relative to each users DocumentRoot, meaning that everyone would need their own /404.html. (at least that's how it seems to work)
I thought he meant that he would like to have ALL sites on his server show the same error message.
Matt
mlightner@site5.com
Learner 09-30-2000, 01:24 PM Hello Site5-Matt,
Felix did mention to have these lines (for the most common errors) in your httpd.conf or srm.conf file (usually found under /etc/httpd/conf/). I guess that makes it server-wide for all domains on the server.
Had the same code been inserted in a .htaccess file into a specific users DocumentRoot, it would pertain to that particular user's domain only.
It seems that when a server encounters common error, it first looks for the .htaccess file to display a customized error (I think this is true for all servers running on Apache).
If it cannot find the relevant code in the .htaccess for a customized common error display, it proceeds to look into the httpd.conf or srm.conf file (usually found under /etc/httpd/conf/).
Felix / Site5-Matt, please correct me if there is an error in my assumption. My knowledge on this subject is just two days fresh :)
Learner
Matt Lightner 09-30-2000, 01:57 PM As far as I can tell, it is relative to the document root that the page exists in.
For example.. if you have the lines that felix suggested in your httpd.conf or srm.conf, the following would happen:
Someone goes to http://www.you.com/page.html
That page doesn't exit
The document root for this site is "/home/you/public_html", and it has no .htaccess file.
The server would see the lines that felix mentioned.
However, it would not load "/path/to/404.html" it would load "/home/you/public_html/path/to/404.html" since the "/" at the beginning does not actually mean an absolute path on the server.. but an absolute path within that site.
At least this is how it has always worked for me. If somebody else knows differently, I would definitely be interested in learning about it!
Matt
mlightner@site5.com
AtlantaWebhost.com 09-30-2000, 02:27 PM You can also put a default .htaccess in the /etc/skel directory. The contents of that directory are duplicated in the home directory of each new account. You could use the same mechanism to propagate default error documents into account directories.
Best regards,
Frank Rietta
Chicken 09-30-2000, 02:43 PM Well, I'm confused... in my srm.conf file, it has a line that points to a directory that doesn't exist. I can't find where it references the actual file which I know is the 404 page. I know where the file is and the directories leading to it, I just can't find where the server is telling it to go there... hmmm.
Side note: I checked both the httpd.conf file and the srm.conf file, maybe I missed it... but I did see something directing a 404 to a directory that doesn't exist. Confused. Maybe I just missed it... Like I said, I know where the file is, and could change it if I wanted to, I just can't figure out where/how the server is telling it to go to that file. Note: this is a RaQ3 so I think the setup is slightly different.
[Edited by Chicken on 09-30-2000 at 02:47 PM]
Matt Lightner 09-30-2000, 02:53 PM Frank,
Great thinking!
Chicken:
What do the lines in your srm.conf file look like? Perhaps I can help you figure out what the server is thinking. :)
Chicken 09-30-2000, 02:57 PM Well when I do a search for srm.conf I find two:
/etc/admserv/conf/srm.conf
/etc/httpd/conf/srm.conf
the top one seems to have the correct path to the error document. What the heck is the bottom one??? It is shorter (by 10 lines) and seem to be nearly identical. The few exceptions I can see are things like this. The paths to the 404 are not correct, and point to a directory that doesn't exist? Hmmm. I guess the httpd srm.conf isn't the one the server is using, eh?
Chicken 09-30-2000, 03:04 PM Ahhhhh, in the httpd srm.conf, there is an Alias which I missed which is from the directory that doesn't exist to the correct one. I guess both of these srm.conf's work together?
Matt Lightner 09-30-2000, 03:17 PM /etc/admserv/conf/srm.conf
/etc/httpd/conf/srm.conf
Interesting. The first is most likely the HTTP server for the server administration utility.
Where is your server hosted? Does it have a "web based server admin" tool? If so, it probably runs a separate copy of Apache, located in /etc/admserv (like.. 'admin server') instead of /etc/httpd.
Try this:
cat /etc/httpd/conf/httpd.conf | grep ^Port
then try this
cat /etc/admserv/conf/httpd.conf | grep ^Port
The one that is running on port 80 is your standard webserver.
The second one is the standard location for httpd.conf. That's probably the one running on port 80. This is the one you should be editing to make changes to your webserver.
If you try to edit the admin server, you could end up breaking something you dont want to :) . Your host probably has it configured to work a certain way.
Matt
mlightner@site5.com
Félix C.Courtemanche 09-30-2000, 03:54 PM ok, lets clarify things:
When the error calls ar in the .srm.conf file, the path is the one of the server, thus if you have your page in
/etc/skel/errors then the path/to/error file is /etc/skel/errors
aslo, the 2 srm.conf file you found, the one with /etc/admsxerv/... is the one used by your Cobalt to run apache as root when you type yourdomain.com/admin or /siteadmin or /personal
The other one is the server running all other web pages on the server.
Yes, there is an alias called /cobalt_error/ or something... it actually points elsewhere, so the easiest way to use different error pages is to change that alias to point it elsewhere.
The server in fact look in the directory that the file is requested and if there are no .htaccess files with the errordocument handle, it will use the server default, be it simply a text error or one that you specified in your srm.conf or httpd.conf file as I specified earlier.
Any other questions?
Félix C.Courtemanche 09-30-2000, 03:57 PM The document root for this site is "/home/you/public_html", and it has no .htaccess file.
The server would see the lines that felix mentioned.
However, it would not load "/path/to/404.html" it would load "/home/you/public_html/path/to/404.html" since the "/" at the beginning does not actually mean an absolute path on the server.. but an absolute path within that site.
[/B]
Just making sure I was clear... when it is in the srm.conf the path are absolute, not relative to the web page at all. in the .htaccess, they are relative to the web root, not the server root.
Chicken 09-30-2000, 04:22 PM Yeah, it's the httpd one... I missed the alias the first time, so when I saw the reference down the srm.conf file I was confused. I still am not sure why they alias it, but it works.
And yep, the server has a CP, and that seems to be what the other file is. I think we're under control now :) I've always known where and how to modify it, but I just wondered how it all worked. I wonder how the whole thing works and am slowly getting more and more info.
Matt Lightner 09-30-2000, 04:26 PM Ok... here's how we have it setup:
in srm.conf:
ErrorDocument 400 /400.shtml
ErrorDocument 401 /401.shtml
ErrorDocument 403 /403.shtml
ErrorDocument 404 /404.shtml
ErrorDocument 500 /500.shtml
To test this out, I setup a test account (with no .htaccess file). I then went to a URL on that site that doesn't exist.. and tailed the apache error log. Here's what I got:
[Sat Sep 30 16:12:14 2000] [error] [client 24.19.134.250] File does not exist: /home/username/public_html/fakepage.html
[Sat Sep 30 16:12:14 2000] [error] [client 24.19.134.250] File does not exist: /home/username/public_html/404.shtml
As you can deduct from the line "File does not exist: /home/username/public_html/404.shtml", apache thinks the error document paths are relative to the doc root.. even though they are given as absolute in srm.conf.
Felix, does yours not work like this? If so, how does your setup differ from what I have outlined here?
Matt
mlightner@site5.com
[Edited by Site5-Matt on 09-30-2000 at 04:28 PM]
Hello,
Three ways to do error redirects.
These go in the httpd.conf config files to become webserver-wide, or in each specific VirtualHost to make them specific to that VirtualHost.
1) Plain Text -- The "s don't get displayed.
ErrorDocument 404 "The server made a boo boo."
2) Local Redirects -- Direct to a file in your web directory. "/" makes it relative to your root file path.
ie. This would point to /home/USERNAME/public_html/missing.html.
ErrorDocument 404 /missing.html
3) External Redirects -- Redirects to a outside URL.
ErrorDocument 404 http://www.someserver.com/missing.html
Regards,
Rory
Félix C.Courtemanche 09-30-2000, 05:07 PM Originally posted by Site5-Matt
[Sat Sep 30 16:12:14 2000] [error] [client 24.19.134.250] File does not exist: /home/username/public_html/fakepage.html
[Sat Sep 30 16:12:14 2000] [error] [client 24.19.134.250] File does not exist: /home/username/public_html/404.shtml
As you can deduct from the line "File does not exist: /home/username/public_html/404.shtml", apache thinks the error document paths are relative to the doc root.. even though they are given as absolute in srm.conf.
Felix, does yours not work like this? If so, how does your setup differ from what I have outlined here?
Try using a file that already exists :)
/path/to/your/web/dir/404.html
that will work just fine... but if your error file does not exist, you get an additionnal 404 error over your first error, thus it gets confused :)
I tell you, and I am sure of what I say here, that the configuration in srm.conf or httpd.conf (outside of virtual tags) is using the srver wide path and not the web ones.
Matt Lightner 09-30-2000, 05:21 PM LOL!
I'll just take your word on that one ;)
Matt
Chicken 09-30-2000, 05:28 PM Originally posted by Rory
2) Local Redirects -- Direct to a file in your web directory. "/" makes it relative to your root file path.
ie.
ErrorDocument 404 /missing.html
This would point to /home/USERNAME/public_html/missing.html.
I read this exact thing in my srm.conf (the 3 ways). I guess what is confusing is the part above. It seems like ti can work both ways according to the example (and when I look at mine with the same info).
just putting "/missing.html" by what you say, would be wrong as that would be at the root of the server. By the way, I know you are right, it just isn't making sense when I look at the example above.
How can "/missing.html" point to /home/USERNAME/public_html/missing.html then? Must be aliased somewhere I suppose or this wouldn't work correct?
Félix C.Courtemanche 09-30-2000, 05:31 PM My guess on this is if that there is no file where you specified it, apache tries to append the web root before it to see if it exists? (but that would be weird)
Anyway, input the right path and it will work fine, guarenteed :)
Matt Lightner 09-30-2000, 05:46 PM Felix,
I have tried setting the document to an actual document.. and yet the error log still appends the current doc root.
ErrorDocument 404 /home/username/public_html/index.html
Where that is an absolute path to a REAL file. The error log then says:
/home/username/public_html/home/username/public_html/index.html
This is from the Apache website:
In the event of a problem or error, Apache can be configured to do one of four things,
output a simple hardcoded error message
output a customized message
redirect to a local URL to handle the problem/error
redirect to an external URL to handle the problem/error
...
URLs can begin with a slash (/) for local URLs, or be a full URL which the client can resolve. Examples:
ErrorDocument 500 http://foo.example.com/cgi-bin/tester
ErrorDocument 404 /cgi-bin/bad_urls.pl
ErrorDocument 401 /subscription_info.html
ErrorDocument 403 "Sorry can't allow you access today
Perhaps you are confusing the "local URL" with an "absolute path", as I have never been able to get it to load a file relative to the root directory on the server (/). It has always been relative to the document root (http://www.whateversite.com/)
Matt
mlightner@site5.com
Chicken 09-30-2000, 05:59 PM Well this is how the Cobalt accomplishes it (in the srm.conf file)...
Alias /cobalt_error/ /usr/admserv/html/.cobalt/error/
then further down...
ErrorDocument 404 /cobalt_error/fileNotFound.html
- Note that the file the server is accessing is actually located at:
/usr/admserv/html/.cobalt/error/fileNotFound.html
I guess I just wonder why it just isn't:
ErrorDocument 404 /usr/admserv/html/.cobalt/error/fileNotFound.html ???
[Edited by Chicken on 09-30-2000 at 06:02 PM]
Matt Lightner 09-30-2000, 06:03 PM Chicken Wrote:
How can "/missing.html" point to /home/USERNAME/public_html/missing.html then? Must be aliased somewhere I suppose or this wouldn't work correct?
Well.. it is an absolute path. It is just not absolute to the SERVER root, but the DOCUMENT root.
For example:
If you put in an HTML page
<img src="/images/image.gif">
Is the server really going to look for /images/image.gif in it's filesystem?
No, of course not. You can not access files above your document root from within your site. It will actually look for the file:
/home/username/public_html/images/image.gif
That's why putting /missing.html will actually look for:
/home/username/public_html/missing.html
Hope I've clarified things.. instead of blurred them even worse ;)
Matt
mlightner@site5.com
Chicken 09-30-2000, 06:06 PM Hope you didn't miss the one I snuck in right before your post...
Matt Lightner 09-30-2000, 06:12 PM Ok..... Thanks to a little help from Chicken (whether you knew it or not) I figured out how to set it up. Just add the following to your srm.conf (or httpd.conf):
--------------------
Alias /errors/ /path/to/your/error/files/
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
---------------------
That's it.
/path/to/your/error/files should contain the default error pages (400.html 401.html, etc).
The reason that this works is because it aliases /errors/ on every document root to the REAL folder that you have the error files stored in. So when the server tries to access:
/home/username/public_html/errors/404.html
it is really accessing
/path/to/your/error/files/404.html
I have tested it out and it works exactly as it should.
NOTE: Be sure that the files in /path/to/your/error/files are world-readable.
Matt
mlightner@site5.com
The alias for the /missing.html is accomplished globally and in each VirtualHost by the "DocumentRoot" directive... :)
Chicken 09-30-2000, 06:23 PM Well, I actually thought it would help you, thogh I didn't fully understand it until you explained it. I just knew it worked :)
So basically, if there WASN'T an alias there at the top, then the server would try to access something like:
/home/username/public_html/usr/admserv/html/.cobalt/error/fileNotFound.html
- Which wouldn't work. (Not sure on that path *exactly*, but something like that anyway, right?)
Matt Lightner 09-30-2000, 06:24 PM Chicken:
I guess I just wonder why it just isn't:
ErrorDocument 404 /usr/admserv/html/.cobalt/error/fileNotFound.html ???
Because if it were this, then file that the server would REALLY look for is:
/home/username/public_html/usr/admserv/html/.cobalt/error/fileNotFound.html
Because the path is absolute relative to the document root that you are in... not the entire server.
Matt
Chicken 09-30-2000, 06:25 PM Originally posted by Rory
The alias for the /missing.html is accomplished globally and in each VirtualHost by the "DocumentRoot" directive... :)
Yeah, I saw that and figured that is how it knows to go to the root of each site. I wasn't sure, but it seemed like the only reason when I looked at the file.
Matt Lightner 09-30-2000, 06:27 PM LOL. We should read the thread *right* before hitting the submit button. We both answered your question. :D
But yeah... you hit it right on. Looks like we both understand it well now. Hehe
Matt
Chicken 09-30-2000, 06:27 PM Heh, well at least I got the path right (we are slipping in posts on eachother)... I get it, but whooo. Interesting how the server accomplishes this.
Chicken 09-30-2000, 06:31 PM Originally posted by Site5-Matt
LOL. We should read the thread *right* before hitting the submit button.
No doubt! Too funny...
Looks like we both understand it well now.
Finally I do, thankx all!
webfors 09-30-2000, 06:51 PM Might sound a little trivial, but would you mind explaining the meaning of each error code?
[Edited by tabernack on 09-30-2000 at 06:53 PM]
Here's a very quick reference to the common ones.
http://www.ncifcrf.gov/communications/networking/netscape/netscape_ts.html
There are others like 101, 201, 300, etc., but none worth mentioning unless you really wanna know.....
webfors 09-30-2000, 07:15 PM Thanks BC,
I'm in the process of making my custom error messages now, following Matt's post above.
Félix C.Courtemanche 09-30-2000, 07:23 PM Yah, my mistake, I forgot to tell you to use an alias to go anywhere in your server instead of appending after the url. I just got a coffee and everything came clear again :)
I am sorry if I was not totally understandable.
Hey Guys,
Thanks for all of your help. I appreciate it. Nothing like a quick class in Apache admin! :>)
~ Marcus
webfors 09-30-2000, 09:04 PM Works great. Thanks everyone!
Chicken 09-30-2000, 09:15 PM Anyone got any ideas for Lesson 2? If you know of some neato tips, I'd like to document them and maybe put up a little site or something. Maybe just personal interest. Though I suppose it should be under Dedicated Servers and not the General Web Hosting forum, heh.
webfors 09-30-2000, 09:25 PM I would love a lesson on different backup techniques. I want to perform daily backups using a second hard drive installed on my server. No raid, just plain old IDE.
What would everyone recommend to perform a quick and simple backup to a second drive?
webfors 09-30-2000, 09:26 PM I'm hoping to write a script that I can run as a cron job to perform this. So, what would be better, tar, cpio, rsync, etc....
Anyone have any ideas?
[Edited by tabernack on 09-30-2000 at 09:37 PM]
Learner 10-01-2000, 02:06 AM Wow... you guys did it again... whooooaaaa!!!!
It seemed like an overload for a little learner like me in the beginning, but as you guys boiled it right down... it all became crystal clear!!!
Okie... Chicken asked for some neato tips... so here is one:
With so many of the newer browser versions getting better at caching content, some browsers may naturally cache your error pages. This could then result in users seeing an error page even if there's no problem.
So I think it would be better to include the following META tags in your error pages to prevent them from being cached:
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="Sun, 1 Jan 12:00:00 GMT">
Learner
Duster 10-01-2000, 02:16 AM That's a good idea. All my custom error pages contain the no cache tags as well
UNIXIELHOST 10-01-2000, 02:42 AM Want get paid while using Error 404 Pages?
Clickfinders.com is the one will pay you money to use thier error 404 pages.
Just a though :)
|