Apache HTTP Server

Protect a directory

Suppose the directory to protect is /private.

  • Create the password file:

    $ htpasswd -bcm /private/.htpasswd guest qwe123
  • Create file /private/.htaccess with contents:

    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /private/.htpasswd
    Require valid-user

Display contents of scripts instead of execute

If you want the .sh, .py, .pl, or .cgi suffixed files to be displayed in the browser as source rather than executed as scripts, simply create a .htaccess file in the directory with contents:

Options +Indexes
Options +FollowSymLinks
<FilesMatch "(\.(sh|py|pl|cgi))$">
  Allow from all
  RemoveHandler .sh .py .pl .cgi
</FilesMatch>

How do I create a self-signed SSL Certificate for testing purposes?

Run the following command, to create server.key and server.crt files:

$ openssl req -new -x509 -nodes -out server.crt -keyout server.key
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Beijing
Locality Name (eg, city) [Default City]:Haidian District
Organization Name (eg, company) [Default Company Ltd]:Example Ltd.
Organizational Unit Name (eg, section) []:Development Division
Common Name (eg, your name or your server's hostname) []:example.com
Email Address []:admin@example.com

These can be used as follows in your httpd.conf file:

SSLCertificateFile    /path/to/this/server.crt
SSLCertificateKeyFile /path/to/this/server.key

Glossary

DSO
Dynamic Shared Object

None: ApacheHttpServer (last edited 2011-07-07 22:32:35 by ZhigangWang)