Help - Search - Members - Calendar
Full Version: Apache Configuration
Invision Power Services > Community Forums > Community Web Design and Coding
Sebastian Mares
Hey guys, I have some questions about my Apache configuration. Here are some lines from my httpd.conf:

CODE
[...]

DocumentRoot "C:/Server/Freigabe"
ScriptAlias /cgi-bin/ "C:/Server/Freigabe/cgi-bin/"
ServerRoot "C:/Server/Programme/HTTP"

<Directory />
    Options FollowSymLinks Includes
    AllowOverride None
    AddOutputFilterByType DEFLATE text/html text/plain text/css
    Header append Vary User-Agent
</Directory>

<Directory "C:/Server/Freigabe">
    Options FollowSymLinks Includes
    AllowOverride All
    AddOutputFilterByType DEFLATE text/html text/plain text/css
    Header append Vary User-Agent
</Directory>

<Directory "C:/Server/Freigabe/cgi-bin">
    AllowOverride None
    Options ExecCGI
    AddOutputFilterByType DEFLATE text/html text/plain text/css
    Header append Vary User-Agent
</Directory>

[...]


The first <Directory> directive, the root, does it refer to the document root or the server root? If it's the directory root, doesn't this mean that I can remove the entire second <Directory> directive?

Also, do subdirectories inherit the options from their parents? For example, if I use "Header append Vary User-Agent" in "/" or "C:/Server/Freigabe", do I also have to specify it in "C:/Server/Freigabe/cgi-bin"?
IAIHMB
Directory containers are relevant to the file system, not the document root, and their directives apply to the specified directory and all sub directories as well. If Apache is installed on the hard drive labeled C then you can get rid of the second directory container. Hope it helps. original.gif
Sebastian Mares
Am I right then to say that the following will give the same results as what I posted in the first post:

CODE
[...]

DocumentRoot "C:/Server/Freigabe"
ScriptAlias /cgi-bin/ "C:/Server/Freigabe/cgi-bin/"
ServerRoot "C:/Server/Programme/HTTP"

<Directory />
    Options FollowSymLinks Includes
    AllowOverride All
    AddOutputFilterByType DEFLATE text/html text/plain text/css
    Header append Vary User-Agent
</Directory>

<Directory "C:/Server/Freigabe/cgi-bin">
    Options ExecCGI
</Directory>

[...]


I use AllowOverride All because I want to be able to override global settings by using .htaccess files and this should be the only change.
IAIHMB
I believe you've got it, yeah.
Sebastian Mares
Great, one more question: is it possible to enable directory listing on a per-IP basis? I want directory listing to be disabled for everyone, except for visitors with IP 123.123.123.123 (of course, the IP will be different tongue.gif).
Brendon Koz
I think you'd use the deny/allow directives. From the "Apache: The Definitive Guide" from O'Reilly:

QUOTE
The order in which the order and deny commands are applied is not set by the order in which they appear in your file. The default order is deny then allow: if a client is excluded by deny, it is excluded unless it matches allow. If neither is matched, the client is granted access.

The order in which these commands is applied can be set by the order directive.


A rather simple search on this should give you the proper results. I only did this once a long, long time ago and did it from reference, I didn't really learn it (as there's not much to learn).


--edit-- I flipped the page:
CODE
<Directory [...]>
order allow,deny
allow from all
deny from 125.234
deny from 123.123.123.123
deny from badguys.com
</Directory>


Actually...what am I doing?

LINK: http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html
I personally prefer the documentation from the 1.x.x series, but whatever. original.gif
Sebastian Mares
I think you got me wrong. What you posted seems to block access to the whole directory if the IP is XYZ. What I want to do is let everyone access a directory, but deny directory listing (Apache usually displays a list of files in the requested directory if no index file was found - when using -Indexes, you get a 404 instead). If the IP is XYZ (this will be replaced with my personal IP address), directory listing should be allowed.
IAIHMB
I don't think that's possible, I just looked through Pro Apache and I couldn't find anything in there either.
Brendon Koz
Sorry Sebastian, I didn't understand what you meant at first, even though you did use the proper vocabulary. original.gif If it can be done, it would have to be done with an .htaccess file. I don't think my WinXP Apache is setup to handle htaccess files, but if it is I'll see what I can come up with later on tonight (much later).

http://httpd.apache.org/docs/1.3/mod/mod_a...tml#indexignore
Sebastian Mares
Thanks! original.gif
Brendon Koz
Okay, so I decided not to go for my run, therefore not needing my shower, cooldown period, and late dinner...so I looked at it sooner than I thought. biggrin.gif

I did in fact have htaccess support enabled in my Win32 dev-server, so I took a look...

NOPE! original.gif Due to how the directives are laid out, I couldn't figure out a straight-out solution for this the way you wanted to do it. You technically *could* use a redirect (in an htaccess) based on IP to a blank HTML file at your root directory and allow directory listing otherwise (globally allow indexes, globally redirect on a 404 unless IP set...might work, not sure if 404 is thrown in this case).

Obviously this all depends on whether you are, or are not using redirect as it is. You could also use a script to display the indexing and then simply edit the PHP to only allow it based on IP -- I would assume this would also require a redirect unless you want to create your own PHP file per directory (which you could do without this script in this case). I'm thinking out loud and typing at the same time so bear with me. original.gif

ALTERNATIVELY:
Create a non-standard port-based virtual host with the same settings as your standard setup, except allow Options Indexes in the virtual host. Granted, someone could guess your port, but it is an option.

I would think the redirect would probably be the easiest/most secure way of doing this, but I don't really understand the redirect engine to help you with it.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.