Difference between revisions of "Apache2"

From RHS Wiki
Jump to navigation Jump to search
Line 27: Line 27:
 
You should also enter in your domain administration panel and create the CNAMES to redirect trafic<br />
 
You should also enter in your domain administration panel and create the CNAMES to redirect trafic<br />
 
to the public ip of this server
 
to the public ip of this server
 
+
== Redirect HTTP to HTTPS ==
 +
sudo nano /etc/apache2/sites-available/redirect_HTTP_to_HTTPS.conf
 +
<nowiki><VirtualHost *:80>
 +
        RewriteEngine on
 +
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
 +
</VirtualHost></nowiki>
 +
sudo ln -s /etc/apache2/sites-available/redirect_HTTP_to_HTTPS.conf /etc/apache2/sites-enable/redirect_HTTP_to_HTTPS
 
== Authentication ==
 
== Authentication ==
  

Revision as of 12:46, 21 March 2018

Web Server for linux.
Paths:
/etc/apache2/sites-available
/etc/apache2/sites-enabled (symbolic links to sites-available/*.conf files)

Virtual Hosts

Apache allows to have multiple web sites on the same server. To do this go to sites-available and create a
.conf file for each host you whant containing the following:

 <VirtualHost *:80>
    ServerAdmin rafael@herrerosolis.com
    DocumentRoot /var/www/webfolder
    ServerName www.yourwebpagename.com
    ServerAlias www.yourwebpagename.com

    ErrorLog /var/www/yourwebfolder/logs/error.log
    
    # Posible values include: debug, info, notice, warn, error, crit.
    # alert, emerg.

    CustomLog /var/www/yourwebfolder/logs/access.log combined

 </VirtualHost>

You should also enter in your domain administration panel and create the CNAMES to redirect trafic
to the public ip of this server

Redirect HTTP to HTTPS

sudo nano /etc/apache2/sites-available/redirect_HTTP_to_HTTPS.conf

<VirtualHost *:80>
        RewriteEngine on
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

sudo ln -s /etc/apache2/sites-available/redirect_HTTP_to_HTTPS.conf /etc/apache2/sites-enable/redirect_HTTP_to_HTTPS

Authentication

Create user account with:

htpasswd -c /usr/local/apache/passwd/passwords rbowen

Protect with the directory directive:

<Directory "/usr/local/apache/htdocs/secret">
    AuthType Basic
    AuthName "Restricted Files"
    # (Following line optional)
    AuthBasicProvider file
    AuthUserFile "/usr/local/apache/passwd/passwords"
    # Require user rbowen
    Require valid-user
</Directory>

See more options at: https://httpd.apache.org/docs/2.4/es/howto/auth.html