LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Getting mad of apache (https://www.linuxquestions.org/questions/linux-software-2/getting-mad-of-apache-99387/)

J_Szucs 10-02-2003 08:38 AM

Getting mad of apache
 
I try to reach a virtual host inside our LAN, which is defined by name ("safehttp.foo.bar") in httpd.conf, but when I type "http://safehttp.foo.bar/" I am taken to directory "/usr/local/www/Web/intranet" instead of the DocumentRoot ("/usr/local/www/Web") I specified in the virtual host definition.

So it looks like the DocumentRoot definition for the safehttp.foo.bar VirtualHost is completely ignored by apache.

What is misconfigured?

Here is an excerpt of my httpd.conf:

# ServerType is either inetd, or standalone. Inetd mode is only supported on
# Unix platforms.
#
ServerType standalone
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/usr/local"
# ServerName allows you to set a host name which is sent back to clients for
# your server if it's different than the one the program would get (i.e., use
# "www" instead of the host's real name).
# RewriteEngine on
# RewriteCond %(REMOTE_HOST) !^.+\.meei\.hu$
# RewriteRule ^(/~.+) https://mail.foo.bar$1 [R,L]
#ServerName new.host.name
ServerName castor.foo.bar
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#DocumentRoot "/usr/local/www/data"
DocumentRoot "/usr/local/www/Web"
#
# Each directory to which Apache has access, can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# permissions.
#
<Directory />
Options +Includes FollowSymLinks
AllowOverride None
</Directory>
#
# This should be changed to whatever you set DocumentRoot to.
#
#<Directory "/usr/local/www/data">
<Directory "/usr/local/www/Web">
#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks MultiViews +Includes

#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride AuthConfig

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>

#
# UserDir: The name of the directory which is appended onto a user's home
# directory if a ~user request is received.
#
<IfModule mod_userdir.c>
UserDir public_html
</IfModule>

#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec +Includes
<Limit GET POST OPTIONS PROPFIND>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>

#
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
<IfModule mod_dir.c>
DirectoryIndex index.html
</IfModule>


#
# UseCanonicalName: (new for 1.3) With this setting turned on, whenever
# Apache needs to construct a self-referencing URL (a URL that refers back
# to the server the response is coming from) it will use ServerName and
# Port to form a "canonical" name. With this setting off, Apache will
# use the hostname:port that the client supplied, when possible. This
# also affects SERVER_NAME and SERVER_PORT in CGI scripts.
#
UseCanonicalName On

#
# TypesConfig describes where the mime.types file (or equivalent) is
# to be found.
#
<IfModule mod_mime.c>
TypesConfig /usr/local/etc/apache/mime.types
</IfModule>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value. If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type. The MIMEMagicFile
# directive tells the module where the hint definitions are located.
# mod_mime_magic is not part of the default server (you have to add
# it yourself with a LoadModule [see the DSO paragraph in the 'Global
# Environment' section], or recompile the server and include mod_mime_magic
# as part of the configuration), so it's enclosed in an <IfModule> container.
# This means that the MIMEMagicFile directive will only be processed if the
# module is part of the server.
#
<IfModule mod_mime_magic.c>
MIMEMagicFile /usr/local/etc/apache/magic
</IfModule>

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

#
# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
#
<IfModule mod_alias.c>

#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So "/icons" isn't aliased in this
# example, only "/icons/"..
#
Alias /icons/ "/usr/local/www/icons/"

<Directory "/usr/local/www/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/usr/local/www/cgi-bin/"

#
# "/usr/local/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/usr/local/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

</IfModule>
# End of aliases.

#
# Redirect allows you to tell clients about documents which used to exist in
# your server's namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
# Format: Redirect old-URI new-URL
#

### Section 3: Virtual Hosts
#
# If you want to use name-based virtual hosts you need to define at
# least one IP address (and port number) for them.
#
#NameVirtualHost 12.34.56.78:80
#NameVirtualHost 12.34.56.78
NameVirtualHost 192.168.226.2

<VirtualHost 192.168.226.2>
ServerAdmin berta@castor.foo.bar
DocumentRoot /usr/local/www/Web/intranet
ServerName intranet.foo.bar
<Directory />
Options Indexes FollowSymLinks +Includes
</Directory>
ErrorLog /var/log/intranet-error.log
</VirtualHost>

<VirtualHost 192.168.226.2>
ServerAdmin berta@castor.foo.bar
DocumentRoot /usr/local/www/Web/public_html
ServerName public.foo.bar
<Directory />
Options Indexes FollowSymLinks +Includes
</Directory>
ErrorLog /var/log/intranet-error.log
</VirtualHost>

<VirtualHost 192.168.226.2>
ServerAdmin berta@castor.foo.bar
DocumentRoot /usr/local/www/Web
ServerName mail.foo.bar
<Directory />
Options +Indexes FollowSymLinks +Includes
</Directory>
ErrorLog /var/log/intranet-error.log
</VirtualHost>

<VirtualHost 192.168.226.2>
ServerAdmin berta@castor.foo.bar
DocumentRoot /usr/local/www/Web
ServerName castor.foo.bar
<Directory />
Options +Indexes FollowSymLinks +Includes
</Directory>
ErrorLog /var/log/intranet-error.log
</VirtualHost>

<VirtualHost 192.168.226.2>
ServerAdmin szucs@foo.bar
DocumentRoot /usr/local/www/Web
ServerName safehttp.foo.bar
ErrorLog /var/log/safehttp-error.log
TransferLog /var/log/safehttp-transfer.log
ScriptAlias /cgi-bin/ /usr/local/www/cgi-bin/
Alias /downloads/ "/usr/local/www/Web/downloads/"
<Directory "/usr/local/www/Web/downloads">
Options +Indexes FollowSymLinks +Includes
</Directory>
</VirtualHost>

#<VirtualHost _default_:*>
#</VirtualHost>

J_Szucs 10-02-2003 09:15 AM

Meanwhile I created directory /usr/local/www/Web/safehttp, and also added the directory definition in httpd.conf.

Now the virtual host definition of safehttp.foo.bar is like others that work.

This one does not work and I do not know why.

david_ross 10-02-2003 02:12 PM

Have you restarted apache?

J_Szucs 10-02-2003 10:55 PM

A hundred times in the past day of debugging...

J_Szucs 10-03-2003 02:18 AM

I know my apache config is messed up, but this actual problem was due to my browser (ie6):
When it is set to use a proxy and it sees that a page is unavailable the first time, it will always return the page unavailable message even if I click the refresh button. So I had to delete all local temporary files, then set my browser not to use the proxy, then to use the proxy again, and the directory showed up.

However, I still have many problems:
I have a cgi script safehttp.foo.bar/cgi-bin/viralator.cgi, that is called by a redirect rule in squirm.patterns. The script is always called from within safehttp.foo.bar/cgi-bin/, and it downloads a file from the web into safehttp.foo.bar/downloads/. If the download is successful, it gives the url to the client, and makes it start an automatic download. This download, however, always fails, as the client gets url intranet.foo.bar/download/filename as the download filename.
So, the virtual server name changes from safehttp to intranet meanwhile.
I could temporarily solve the matter by symlinking safehttp/download to intranet/download, this, however, is not the correct solution.

Because of such strange changes in the virtual hostnames, in my effort to make things work somehow, I already had to make many symlinks from anywhere to anywhere in the past; so my DocumentRoots now contain scripts, my cgi-bin directories contain documents and icons; php scripts only work in DocumentRoots, while .pl scripts work in /cgi-bin/, too, but their references point out to other virtual hosts; so the whole thing is messed up as it is.

Why are virtual host references changed during the communication between the server and the clients?

david_ross 10-04-2003 01:42 PM

The server will always send back the name by which it was accessed. Perhaps you need to make sure it is always accessed as safehttp with what ever link you use to start with or during the script process.

J_Szucs 10-04-2003 04:40 PM

Quote:

Perhaps you need to make sure it is always accessed as safehttp with what ever link you use to start with or during the script process.
Naturally, I made it sure:
The script is invoked the first time from squid (and squirm), via an url rewrite rule, where any url ending e.g. with .exe is rewritten to point to the script, so the safehttp.foo.bar server name is hardcoded in the rewritten url. Because of this, there is no problem with the first invocation of the script; it is always successful.
The problem is that the script generates pages and places hyperlinks or other references to itself or to files on the same server on these generated pages, which references all seem to point to the wrong servername.
When placing these references on any generated page, the script relies on apache: it uses the "servername" server variable provided by apache. So, I think it is apache to be blaimed.
I could edit the perl script and hardcode the safehttp.foo.bar servername in it, but I need a more general solution, as the problem not only concerns this script, but all scripts in any virtual servers defined.

david_ross 10-05-2003 06:51 AM

That is what I meant by "during the script process". Perhaps you could use the referer attribute. Will that always tell you the name of the server that made the inital request?

rajbaxi 11-21-2003 01:47 AM

Have you checked permissions on the directory? Maybe the virtualhost can't resolve safehttp.foo.bar and it goes back to the default page? Are you running a DNS server?


All times are GMT -5. The time now is 09:20 AM.