This shows you the differences between two versions of the page.
— |
unix:webmastering [2008/09/04 11:38] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Webmastering ====== | ||
+ | Websites have been a hobby of mine since I was about 15, and over time I've started to do some fairly advanced things to take care of simple, usually annoying, problems I encounter. This section is intended to serve as a reminder to myself of those tricks, and possibly of use to others as well. | ||
+ | |||
+ | ===== Monitoring logs during development ===== | ||
+ | It's really useful to be able to watch the error log from the webserver when you are developing a site, it'd be even more useful if you could be alerted when a new error has been logged. | ||
+ | |||
+ | <code bash> | ||
+ | tail -f error.log | grep -v --line-buffered favicon.ico | sed ' | ||
+ | </ | ||
+ | |||
+ | First, open the log and follow appends to it, then filter this through grep and remove any lines with " | ||
+ | |||
+ | :!: **NB:** It is important to use the " | ||
+ | |||
+ | ===== " | ||
+ | This one is a weird problem I came accross when trying to add some fancy url rewriting to a site --- the plan was to have flat links such as "/ | ||
+ | |||
+ | The culprit? **'' | ||
+ | < | ||
+ | Content-Location: | ||
+ | Vary: negotiate | ||
+ | TCN: choice | ||
+ | </ | ||
+ | and this would only happen if adding " | ||
+ | |||
+ | Commenting out mod_negotiation and it's settings (LanguagePriority and ForceLanguagePriority) from my apache configuration fixed this and the request now results in 404 Not Found as it should. So, back to playing with the Rewrite Engine | ||
+ | |||
+ | |||
+ | ===== Content-Disposition ===== | ||
+ | The upshot of the problems I encountered in the previous section is that I discovered the '' | ||
+ | |||
+ | See [[http:// | ||
+ | |||
+ | ===== Upgrading & Testing a live server ===== | ||
+ | When developing a website, it is common to have two separate servers: development and live. However, problems arise when you are upgrading an existing side to a new, incompatible one. I use the trick below to over come this. | ||
+ | |||
+ | ==== The plan ==== | ||
+ | |||
+ | We're going to change our browser to report a different name (technically "User Agent" | ||
+ | |||
+ | For the following example I have a plain HTML file called '' | ||
+ | |||
+ | === Configuring the server === | ||
+ | First we'll set the server to redirect everyone to a notice page about the maintenance, | ||
+ | |||
+ | :!: **Note:** //You need to have '' | ||
+ | |||
+ | Add the following lines near the top of your site's ''/ | ||
+ | <code conf> | ||
+ | ## Enable the URL rewriting engine | ||
+ | RewriteEngine on | ||
+ | Options +FollowSymlinks | ||
+ | |||
+ | ## Send non-developers to a "site down for maintenance" | ||
+ | RewriteCond %{HTTP_USER_AGENT} !^RobM.*$ | ||
+ | RewriteRule .* DownTime.html | ||
+ | |||
+ | ## Normal .htaccess content below this line | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Notes | ||
+ | * You need '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * So '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | === Getting your browser ready === | ||
+ | I hear Opera browser has built in support for changing the User Agent, so you can just use that. In Firefox you'll want the [[http:// | ||
+ | |||
+ | So I've now changed my User Agent to " | ||
+ | |||
+ | == | ||
+ | |||
+ | So with some luck, the general public will be seeing DownTime.html for any request them make, and you'll be seeing the site as " | ||
+ | |||
+ | ===== Migrating your site to a wiki ===== | ||
+ | Just a quick aside related to the above --- when you move your content into a wiki everyone' | ||
+ | |||
+ | <code bash> | ||
+ | RewriteRule ^Events.html$ | ||
+ | RewriteRule ^Events_Schedule.php$ | ||
+ | RewriteRule ^Events_Schedule_Past.php$ | ||
+ | RewriteRule ^Events_Schedule_Static.php$ | ||
+ | RewriteRule ^Events_SocRunnings.php$ | ||
+ | |||
+ | RewriteRule ^ArtMedia.html$ | ||
+ | RewriteRule ^ImproManga.php$ | ||
+ | ... | ||
+ | |||
+ | ## DokuWiki use_rewrite handler | ||
+ | RewriteCond %{REQUEST_FILENAME} | ||
+ | RewriteCond %{REQUEST_FILENAME} | ||
+ | RewriteRule (.*) wiki/ | ||
+ | </ | ||
+ | |||
+ | What this does is compare the left-hand side regular expression against the URL request, and change any matching part to the right-hand side when it can; so by the time it get to the bottom of the file the DokuWiki rewrite directives recieve a request for a (virtual) wiki page. | ||
+ | |||
+ | ===== Per-Host Configurations for lighttpd ===== | ||
+ | While using '' | ||
+ | |||
+ | Add the following to ''/ | ||
+ | <code bash> | ||
+ | ## Load per-vhost configurations | ||
+ | include_shell "/ | ||
+ | </ | ||
+ | |||
+ | And create a new file at ''/ | ||
+ | <code python> | ||
+ | # | ||
+ | |||
+ | """ | ||
+ | Generates per-vhost configuration directives from conf files found in the root | ||
+ | of each vhost | ||
+ | |||
+ | Add the following line to / | ||
+ | |||
+ | include_shell "/ | ||
+ | """ | ||
+ | |||
+ | import os, sys | ||
+ | |||
+ | basedir = os.path.dirname(sys.argv[0]) | ||
+ | dirlist = os.walk(basedir).next()[1] | ||
+ | |||
+ | for dir in dirlist: | ||
+ | conf = os.path.join(basedir, | ||
+ | if os.path.exists(conf): | ||
+ | f = file(conf) | ||
+ | conf_data = f.read() | ||
+ | f.close() | ||
+ | print """ | ||
+ | </ | ||
+ | |||
+ | The directory layout this was used in was as follows: | ||
+ | |||
+ | < | ||
+ | /var/www | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | where ''/ | ||
+ | |||
+ | <code python> | ||
+ | # deny access completly to these | ||
+ | $HTTP[" | ||
+ | $HTTP[" | ||
+ | $HTTP[" | ||
+ | </ | ||
+ | |||
+ | and the script produces the following output when run: | ||
+ | |||
+ | <code python> | ||
+ | $HTTP[" | ||
+ | # deny access completly to these | ||
+ | $HTTP[" | ||
+ | $HTTP[" | ||
+ | $HTTP[" | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Changing the default umask for Lighttpd + PHP ===== | ||
+ | It doesn' | ||
+ | |||
+ | * Use PHP's " | ||
+ | * Change the umask of the process which launches your webserver. E.g. edit ''/ | ||