2008-09-30 01:09VirtualHost problem plus Multiple MySQL MAXesAs mentioned last time, my trouble with Apache didn’t end with mod_rewrite rules on my blog. I have Apache installed on my home PC (firewalled off) and have been receiving warning messages from it in emails caused by a logrotate cronjob which runs every week. The same warning appears when the server is restarted, and while it is not critical, it is something I wanted to understand and avoid. Also, in case this post is too short or not varied enough (and because I have an unhelpful backlog of little comments I’d like to blog), I will include below a little trick for getting MySQL to produce a set of results where each row contains the name of a table and MAX(foo) for some field foo in that table. (Unfortunately the MySQL trick doesn’t enumerate the tables for you and the length of the query’s SQL scales linearly with the number of rows, but it is slightly nicer than running several queries which each produce one row, then parsing and combining the results). VirtualHost problemQuite simply, the message given in the email was: /etc/cron.daily/logrotate: [Sun Sep 28 06:45:37 2008] [warn] NameVirtualHost *:80 has no VirtualHosts which suggests you need to look into the VirtualHosts you have configured. A handy tip for Apache is to use a utility which parses your configuration files and outputs its understanding of your VirtualHosts, but I think this utility works slightly differently in Debian, so here is what I did on a root shell: # apache2ctl -S and it produced the output: [Sun Sep 28 12:24:22 2008] [warn] NameVirtualHost *:80 has no VirtualHosts VirtualHost configuration: wildcard NameVirtualHosts and default servers: *:443 is a NameVirtualHost default server localhost.localdomain (/etc/apache2/sites-enabled/local-ssl:2) port 443 namevhost localhost.localdomain (/etc/apache2/sites-enabled/ssl:2) *:80 is a NameVirtualHost default server localhost.localdomain (/etc/apache2/sites-enabled/local-http:2) port 80 namevhost localhost.localdomain (/etc/apache2/sites-enabled/http:2) Syntax OK It is a little worrying that even this command produces a warning, but at least it says the syntax is valid. As you can see from the output, I do indeed have two NameVirtualHosts configured, one on port 80 and one on port 443, the latter configured to use SSL. This means that if I were to allow access from outside the firewall, I could do so with an encrypted connection, while not burdening my machine with the cryptographic overhead when connecting locally. The sort of sites I was finding on Google did suggest that this configuration was quite common, and possibly quite commonly associated with the problem I was experiencing, but I think the warning can occur in simpler setups. Anyway, the online results and my sleuthing lead me to look for references on my computer to this troublesome *:80 figure. I ran grep -ri “*:80” /etc/apache2 and received precisely two responses: ./sites-available/default:<VirtualHost *:80> ./ports.conf:NameVirtualHost *:80 The first of these I had already looked into, and despite it being a likely candidate, I couldn’t find a suitable edit for it to fix the problem. The second, however, I had never even thought to look in as I had no reason to think it could be related to the first, but from the comment at the top of it presumably the creator of the file knew of the connection: # If you just change the port or add more ports here, you will likely also # have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default NameVirtualHost *:80 Listen 80 <IfModule mod_ssl.c> # SSL name based virtual hosts are not yet supported, therefore no # NameVirtualHost statement here Listen 443 </IfModule> It turned out, then, that the one-character edit necessary was to simply add a # at the beginning of the NameVirtualHost line, commenting it out, and the server could then be restarted silently. The only remaining thing to say is that although I didn’t find (or remember to record) any site which ultimately helped me find this solution, I did find a nice-looking blog post from Simplificator.com that had an answer that didn’t help me but might help other people. Multiple MySQL MAXesWell, it appears this post hasn’t been that short after all, but as there has been some delay in getting it to an acceptable condition, it is only fair that I don’t delay this hint any longer. As mentioned at the beginning, this is just a trick for displaying several rather boring values as the answer to one query. It works not just for the MAX(…) function, but I came up with it while trying to find the maximum value of the auto-increment id columns of several tables. The reason for wanting this was to get a sense of the pattern of INSERTs happening on those tables. Perhaps a more meaningful number would have been the COUNT(…), but I assumed that calculating MAX(id) would be faster, given that there was an index on the id column. The query, then, is: SELECT tablename, themax FROM ( (SELECT "first_table" AS tablename, MAX(id) AS themax FROM first_table) UNION (SELECT "second_table" AS tablename, MAX(id) AS themax FROM second_table) ) theunion;
and it produces output like this: +———————————+——————-+ | tablename | themax | +———————————+——————-+ | first_table | 13303586 | | second_table | 93305912 | +———————————+——————-+ Obviously this can be extended, if you don’t mind writing a longer query, but that starts to get boring after a while. SQL may not be a Turing complete programming language, but what would it be like if it was a meta-language, allowing you to generate the text of the query using results from subqueries? Trackbacks
Trackback specific URI for this entry
No Trackbacks
|
QuicksearchCategoriesSyndicate This BlogBlog Administration |