This is a short "recipe" article explaining how to configure basic authentication for the following setup:
- Apache Tomcat with some application that need be partially password-protected
- Apache HTTP Server 2.4 as a proxy
- CentOS 7 Linux server
Steps
- Copy certificates into /etc/ssl/certs/ivanlagunov.com
- Create symlink:
- Install Apache mod_ssl
- Create file with user credentials for basic authentication
- Modify VirtualHost
- Restart Apache
cd /etc/httpd sudo ln -s /etc/ssl/certs/ivanlagunov.com
sudo yum -y install mod_ssl
sudo htpasswd -c /usr/local/apache/password/.htpasswd_application username
sudo vi /etc/httpd/conf.d/vhosts.confThe following are examples of virtual hosts:
<VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/httpd/ivanlagunov.com/Answer/ivanlagunov.com.crt SSLCertificateKeyFile /etc/httpd/ivanlagunov.com/Request/ivanlagunov.com.key SSLCertificateChainFile /etc/httpd/ivanlagunov.com/Answer/Linux/ivanlagunov.com.ca-bundle ServerName ivanlagunov.com # Password-protected part of the application is available under HTTPS <Location /application/protected_service> ProxyPass ajp://localhost:8009/application/protected_service AuthType Basic AuthName "Protected application" # By default, credentials are loaded from the file # There are smarter alternatives # As a default, the following directive can be omitted AuthBasicProvider file # Path to the file with user credentials AuthUserFile /usr/local/apache/password/.htpasswd_application # If Authorization header is not unset # Tomcat will return HTTP 401 Unauthorized RequestHeader unset "Authorization" # Require any valid user, can be limited to specific users Require valid-user </Location> </VirtualHost> <VirtualHost *:80> ServerName ivanlagunov.com # The whole application is available under HTTP ProxyPass /application ajp://localhost:8009/application </VirtualHost>
sudo service httpd restart
Results
As a result, the following URLs will be accessible without password:
- http://ivanlagunov.com/application
- http://ivanlagunov.com/application/protected_service
- https://ivanlagunov.com/application
- https://ivanlagunov.com/application/protected_service
Comments
Post a Comment