Apache: Difference between revisions

From miki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:
DirectoryIndex index.php index.html # Will serve php version first
DirectoryIndex index.php index.html # Will serve php version first
DirectoryIndex mycustomindex.html # To point to specific file when browsing directory (no directory listing)
DirectoryIndex mycustomindex.html # To point to specific file when browsing directory (no directory listing)
</source>

== HTTPS ==
From [http://beginlinux.com/blog/2009/01/ssl-on-ubuntu-810-apache2/]. Assumptions:
* Already a website present at <tt>/var/www</tt>
* Package <tt>ssl-cert</tt> installed (that create snakeoil (i.e. self-signed) certificates in <tt>/etc/ssl</tt>)
<source lang="bash">
# Load and enable SSL module
sudo a2enmod ssl
sudo /etc/init.d/apache2 force-reload

# Edit file
sudo vim /etc/apache2/sites-available/default-ssl
# ... and change lines as follows (for key/cert we use the snakeoil ones):
# SSLEngine on
# SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire

#Enable the default SSL site:
sudo a2ensite default-ssl

# Tell Apache to reload its configuration:
sudo /etc/init.d/apache2 reload
</source>


To also add user authentication, add the following lines to either
* File <tt>.htaccess</tt> in website directory
* Section <tt>&lt;Directory /&gt;</tt> in <tt>/etc/apache2/sites-available/default-ssl</tt>:
<source lang="bash">
AuthType Basic
AuthName "default"
AuthUserFile /var/www/nxl67002ux.ssl.passwd
Require valid-user
</source>

Then create the password file with the command <code>[http://httpd.apache.org/docs/2.0/programs/htpasswd.html htpasswd] -c filename.passwd username</code>

Finally, reload apache2:
<source lang="bash">
sudo /etc/init.d/apache2 reload
</source>
</source>

Revision as of 15:38, 13 July 2011

Enabling .htaccess files

Check that you don't have an overall 'AllowOverride None in Apache's configuration file (/etc/apache2/httpd.conf)

Tags

DirectoryIndex

  • Use DirectoryIndex to change list of default name of index file while browsing directory
DirectoryIndex index.php index.html         # Will serve php version first
DirectoryIndex mycustomindex.html           # To point to specific file when browsing directory (no directory listing)

HTTPS

From [1]. Assumptions:

  • Already a website present at /var/www
  • Package ssl-cert installed (that create snakeoil (i.e. self-signed) certificates in /etc/ssl)
# Load and enable SSL module
sudo a2enmod ssl
sudo /etc/init.d/apache2 force-reload

# Edit file
sudo vim /etc/apache2/sites-available/default-ssl
# ... and change lines as follows (for key/cert we use the snakeoil ones):
#  SSLEngine on
#  SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire

#Enable the default SSL site:
sudo a2ensite default-ssl

# Tell Apache to reload its configuration:
sudo /etc/init.d/apache2 reload


To also add user authentication, add the following lines to either

  • File .htaccess in website directory
  • Section <Directory /> in /etc/apache2/sites-available/default-ssl:
AuthType Basic
AuthName "default"
AuthUserFile /var/www/nxl67002ux.ssl.passwd
Require valid-user

Then create the password file with the command htpasswd -c filename.passwd username

Finally, reload apache2:

sudo /etc/init.d/apache2 reload