580 | | = Secure the Web Sites with Let's Encrypt = |
| 580 | = Securing Apache = |
| 581 | |
| 582 | == Securing Apache with Basic Authentication == |
| 583 | |
| 584 | Apache provides some inbuilt directory level authentication mechanism. Though this is not a most secure authentication method, this could be useful. To do this you need to create .htaccess within the web directory that you need to be password protected. For our lab we will protect our whole web site with this method. So let's create a .htaccess file on the document root. |
| 585 | |
| 586 | {{{ |
| 587 | cd /var/www/web.your_domain.com/public_html |
| 588 | sudo nano .htaccess |
| 589 | }} |
| 590 | |
| 591 | And add below, |
| 592 | |
| 593 | {{{ |
| 594 | AuthType Basic |
| 595 | AuthName "Authentication Required" |
| 596 | AuthUserFile "/var/www/web.your_domain.com/.htpasswd" |
| 597 | require valid-user |
| 598 | }}} |
| 599 | |
| 600 | Now you will add users using the htpasswd utility to a file call .htpasswd. Make sure this file to keep outside the document root. |
| 601 | |
| 602 | {{{ |
| 603 | htpasswd -c /var/www/web.your_domain.com/.htpasswd user |
| 604 | }}} |
| 605 | |
| 606 | If you need to add another user please avoid the option -c, |
| 607 | |
| 608 | {{{ |
| 609 | htpasswd -c /var/www/web.your_domain.com/.htpasswd user2 |
| 610 | }}} |
| 611 | |
| 612 | Now refresh the site and you will be asked the password to enter the site. |
| 613 | |
| 614 | [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web33.png)]] |
| 615 | |
| 616 | == Secure the Web Sites with Let's Encrypt == |