RHEL 9.2 - Deploying Web Servers and Reverse Proxies
RHEL 9.2 - Deploying Web Servers and Reverse Proxies
Setting up and configuring web servers and reverse proxies in Red Hat Enterprise
Linux 9
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
Configure and run the Apache HTTP web server, the NGINX web server, or the Squid caching proxy
server on Red Hat Enterprise Linux 9. Configure TLS encryption. Configure Kerberos authentication
for the Apache HTTP web server. Set up NGINX as a reverse proxy for the HTTP traffic or as an
HTTP load balancer. Configure Squid as a caching proxy without authentication, with LDAP
authentication, or with Kerberos authentication.
Table of Contents
Table of Contents
. . . . . . . . . .OPEN
MAKING . . . . . . SOURCE
. . . . . . . . . .MORE
. . . . . . .INCLUSIVE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . .
. . . . . . . . . . . . . FEEDBACK
PROVIDING . . . . . . . . . . . . ON
. . . .RED
. . . . .HAT
. . . . .DOCUMENTATION
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . .
.CHAPTER
. . . . . . . . . . 1.. .SETTING
. . . . . . . . . .UP
. . . THE
. . . . .APACHE
. . . . . . . . . HTTP
. . . . . . .WEB
. . . . .SERVER
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5. . . . . . . . . . . . .
1.1. INTRODUCTION TO THE APACHE HTTP WEB SERVER 5
1.2. NOTABLE CHANGES IN THE APACHE HTTP SERVER 5
1.3. THE APACHE CONFIGURATION FILES 6
1.4. MANAGING THE HTTPD SERVICE 6
1.5. SETTING UP A SINGLE-INSTANCE APACHE HTTP SERVER 7
1.6. CONFIGURING APACHE NAME-BASED VIRTUAL HOSTS 8
1.7. CONFIGURING KERBEROS AUTHENTICATION FOR THE APACHE HTTP WEB SERVER 10
1.7.1. Setting up GSS-Proxy in an IdM environment 10
1.7.2. Configuring Kerberos authentication for a directory shared by the Apache HTTP web server 11
1.8. CONFIGURING TLS ENCRYPTION ON AN APACHE HTTP SERVER 12
1.8.1. Adding TLS encryption to an Apache HTTP Server 12
1.8.2. Setting the supported TLS protocol versions on an Apache HTTP Server 14
1.8.3. Setting the supported ciphers on an Apache HTTP Server 15
1.9. CONFIGURING TLS CLIENT CERTIFICATE AUTHENTICATION 16
1.10. SECURING WEB APPLICATIONS ON A WEB SERVER USING MODSECURITY 17
1.10.1. Deploying the ModSecurity web-based application firewall for Apache 17
1.10.2. Adding a custom rule to ModSecurity 18
1.11. INSTALLING THE APACHE HTTP SERVER MANUAL 19
1.12. WORKING WITH APACHE MODULES 20
1.12.1. Loading a DSO module 20
1.12.2. Compiling a custom Apache module 21
1.13. EXPORTING A PRIVATE KEY AND CERTIFICATES FROM AN NSS DATABASE TO USE THEM IN AN
APACHE WEB SERVER CONFIGURATION 21
1.14. ADDITIONAL RESOURCES 21
.CHAPTER
. . . . . . . . . . 2.
. . SETTING
. . . . . . . . . . UP
. . . .AND
. . . . .CONFIGURING
. . . . . . . . . . . . . . . .NGINX
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
..............
2.1. INSTALLING AND PREPARING NGINX 23
2.2. CONFIGURING NGINX AS A WEB SERVER THAT PROVIDES DIFFERENT CONTENT FOR DIFFERENT
DOMAINS 25
2.3. ADDING TLS ENCRYPTION TO AN NGINX WEB SERVER 27
2.4. CONFIGURING NGINX AS A REVERSE PROXY FOR THE HTTP TRAFFIC 28
2.5. CONFIGURING NGINX AS AN HTTP LOAD BALANCER 29
2.6. ADDITIONAL RESOURCES 30
.CHAPTER
. . . . . . . . . . 3.
. . CONFIGURING
. . . . . . . . . . . . . . . . THE
. . . . . SQUID
. . . . . . . .CACHING
. . . . . . . . . .PROXY
. . . . . . . . SERVER
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
..............
3.1. SETTING UP SQUID AS A CACHING PROXY WITHOUT AUTHENTICATION 31
3.2. SETTING UP SQUID AS A CACHING PROXY WITH LDAP AUTHENTICATION 33
3.3. SETTING UP SQUID AS A CACHING PROXY WITH KERBEROS AUTHENTICATION 36
3.4. CONFIGURING A DOMAIN DENY LIST IN SQUID 39
3.5. CONFIGURING THE SQUID SERVICE TO LISTEN ON A SPECIFIC PORT OR IP ADDRESS 40
3.6. ADDITIONAL RESOURCES 41
1
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
2
MAKING OPEN SOURCE MORE INCLUSIVE
3
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
1. View the documentation in the Multi-page HTML format and ensure that you see the
Feedback button in the upper right corner after the page fully loads.
2. Use your cursor to highlight the part of the text that you want to comment on.
3. Click the Add Feedback button that appears near the highlighted text.
4. Enter your suggestion for improvement in the Description field. Include links to the relevant
parts of the documentation.
4
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
The Apache HTTP Server, httpd, is an open source web server developed by the Apache Software
Foundation.
If you are upgrading from a previous release of Red Hat Enterprise Linux, you have to update the httpd
service configuration accordingly. This section reviews some of the newly added features, and guides
you through the update of prior configuration files.
The apachectl command now fails instead of giving a warning if you pass additional
arguments.
The apachectl configtest command now executes the httpd -t command without changing
the SELinux context.
The apachectl(8) man page in RHEL now fully documents differences from upstream
apachectl.
Apache modules:
Other changes:
Kernel thread IDs are now used directly in error log messages, making them both accurate
and more concise.
5
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
There are no backwards-incompatible changes to the httpd module API since RHEL 8.
Apache HTTP Server 2.4 is the initial version of this Application Stream, which you can install easily as an
RPM package.
Path Description
Although the default configuration is suitable for most situations, you can use also other configuration
options. For any changes to take effect, restart the web server first.
To check the configuration for possible errors, type the following at a shell prompt:
# apachectl configtest
Syntax OK
To make the recovery from mistakes easier, make a copy of the original file before editing it.
Prerequisites
Procedure
6
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
Follow the procedure in this section if the web server should provide the same content for all domains
associated with the server. If you want to provide different content for different domains, set up name-
based virtual hosts. For details, see Configuring Apache name-based virtual hosts .
Procedure
2. If you use firewalld, open the TCP port 80 in the local firewall:
NOTE
Verification steps
7
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
Additional resources
The procedure in this section describes setting up a virtual host for both the example.com and
example.net domain with separate document root directories. Both virtual hosts serve static HTML
content.
Prerequisites
Clients and the web server resolve the example.com and example.net domain to the IP
address of the web server.
Note that you must manually add these entries to your DNS server.
Procedure
a. Append the following virtual host configuration for the example.com domain:
<VirtualHost *:80>
DocumentRoot "/var/www/example.com/"
ServerName example.com
CustomLog /var/log/httpd/example.com_access.log combined
ErrorLog /var/log/httpd/example.com_error.log
</VirtualHost>
All settings in the <VirtualHost *:80> directive are specific for this virtual host.
DocumentRoot sets the path to the web content of the virtual host.
ServerName sets the domains for which this virtual host serves content.
To set multiple domains, add the ServerAlias parameter to the configuration and
specify the additional domains separated with a space in this parameter.
CustomLog sets the path to the access log of the virtual host.
ErrorLog sets the path to the error log of the virtual host.
NOTE
8
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
NOTE
Apache uses the first virtual host found in the configuration also for
requests that do not match any domain set in the ServerName and
ServerAlias parameters. This also includes requests sent to the IP
address of the server.
<VirtualHost *:80>
DocumentRoot "/var/www/example.net/"
ServerName example.net
CustomLog /var/log/httpd/example.net_access.log combined
ErrorLog /var/log/httpd/example.net_error.log
</VirtualHost>
# mkdir /var/www/example.com/
# mkdir /var/www/example.net/
5. If you set paths in the DocumentRoot parameters that are not within /var/www/, set the
httpd_sys_content_t context on both document roots:
Note that you must install the policycoreutils-python-utils package to run the restorecon
command.
Verification steps
2. Use a browser and connect to http://example.com. The web server shows the example file from
the example.com virtual host.
9
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
3. Use a browser and connect to http://example.net. The web server shows the example file from
the example.net virtual host.
Additional resources
NOTE
Prerequisites
The Apache web server is set up and the httpd service is running.
Procedure
2. Retrieve the keytab for the principal stored in the /etc/gssproxy/http.keytab file:
This step sets permissions to 400, thus only the root user has access to the keytab file. The
apache user does not.
[service/HTTP]
mechs = krb5
cred_store = keytab:/etc/gssproxy/http.keytab
cred_store = ccache:/var/lib/gssproxy/clients/krb5cc_%U
euid = apache
10
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
Additional resources
Prerequisites
Procedure
<Location /var/www/html/private>
AuthType GSSAPI
AuthName "GSSAPI Login"
Require valid-user
</Location>
.include /lib/systemd/system/httpd.service
[Service]
Environment=GSS_USE_PROXY=1
# systemctl daemon-reload
Verification steps
# kinit
11
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
Prerequisites
Prerequisites
The TLS certificate is stored in the /etc/pki/tls/certs/example.com.crt file. If you use a different
path, adapt the corresponding steps of the procedure.
The CA certificate is stored in the /etc/pki/tls/certs/ca.crt file. If you use a different path, adapt
the corresponding steps of the procedure.
Clients and the web server resolve the host name of the server to the IP address of the web
server.
Procedure
2. Edit the /etc/httpd/conf.d/ssl.conf file and add the following settings to the <VirtualHost
_default_:443> directive:
ServerName example.com
IMPORTANT
The server name must match the entry set in the Common Name field of the
certificate.
b. Optional: If the certificate contains additional host names in the Subject Alt Names (SAN)
12
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
b. Optional: If the certificate contains additional host names in the Subject Alt Names (SAN)
field, you can configure mod_ssl to provide TLS encryption also for these host names. To
configure this, add the ServerAliases parameter with corresponding names:
c. Set the paths to the private key, the server certificate, and the CA certificate:
SSLCertificateKeyFile "/etc/pki/tls/private/example.com.key"
SSLCertificateFile "/etc/pki/tls/certs/example.com.crt"
SSLCACertificateFile "/etc/pki/tls/certs/ca.crt"
3. For security reasons, configure that only the root user can access the private key file:
WARNING
NOTE
If you protected the private key file with a password, you must enter this
password each time when the httpd service starts.
Verification steps
Additional resources
SSL/TLS Encryption
13
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
1.8.2. Setting the supported TLS protocol versions on an Apache HTTP Server
By default, the Apache HTTP Server on RHEL uses the system-wide crypto policy that defines safe
default values, which are also compatible with recent browsers. For example, the DEFAULT policy
defines that only the TLSv1.2 and TLSv1.3 protocol versions are enabled in apache.
This section describes how to manually configure which TLS protocol versions your Apache HTTP Server
supports. Follow the procedure if your environment requires to enable only specific TLS protocol
versions, for example:
If your environment requires that clients can also use the weak TLS1 (TLSv1.0) or TLS1.1
protocol.
If you want to configure that Apache only supports the TLSv1.2 or TLSv1.3 protocol.
Prerequisites
TLS encryption is enabled on the server as described in Adding TLS encryption to an Apache
HTTP server.
Procedure
1. Edit the /etc/httpd/conf/httpd.conf file, and add the following setting to the <VirtualHost>
directive for which you want to set the TLS protocol version. For example, to enable only the
TLSv1.3 protocol:
Verification steps
1. Use the following command to verify that the server supports TLSv1.3:
2. Use the following command to verify that the server does not support TLSv1.2:
If the server does not support the protocol, the command returns an error:
Additional resources
14
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
For further details about the SSLProtocol parameter, refer to the mod_ssl documentation in
the Apache manual: Installing the Apache HTTP server manual .
This section describes how to manually configure which ciphers your Apache HTTP Server supports.
Follow the procedure if your environment requires specific ciphers.
Prerequisites
TLS encryption is enabled on the server as described in Adding TLS encryption to an Apache
HTTP server.
Procedure
1. Edit the /etc/httpd/conf/httpd.conf file, and add the SSLCipherSuite parameter to the
<VirtualHost> directive for which you want to set the TLS ciphers:
SSLCipherSuite
"EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:!SHA1:!SHA256"
Verification steps
15
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
Additional resources
SSLCipherSuite
If the Apache HTTP Server uses the TLS 1.3 protocol, certain clients require additional configuration.
For example, in Firefox, set the security.tls.enable_post_handshake_auth parameter in the
about:config menu to true. For further details, see Transport Layer Security version 1.3 in Red Hat
Enterprise Linux 8.
Prerequisites
TLS encryption is enabled on the server as described in Adding TLS encryption to an Apache
HTTP server.
Procedure
1. Edit the /etc/httpd/conf/httpd.conf file and add the following settings to the <VirtualHost>
directive for which you want to configure client authentication:
<Directory "/var/www/html/Example/">
SSLVerifyClient require
</Directory>
The SSLVerifyClient require setting defines that the server must successfully validate the
client certificate before the client can access the content in the /var/www/html/Example/
directory.
Verification steps
1. Use the curl utility to access the https://example.com/Example/ URL without client
authentication:
$ curl https://example.com/Example/
curl: (56) OpenSSL SSL_read: error:1409445C:SSL routines:ssl3_read_bytes:tlsv13 **alert
certificate required**, errno 0
16
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
The error indicates that the web server requires a client certificate authentication.
2. Pass the client private key and certificate, as well as the CA certificate to curl to access the
same URL with client authentication:
If the request succeeds, curl displays the index.html file stored in the /var/www/html/Example/
directory.
Additional resources
mod_ssl configuration
The mod_security-crs package contains the core rule set (CRS) with rules against cross-website
scripting, bad user agents, SQL injection, Trojans, session hijacking, and other exploits.
Procedure
Verification
1. Verify that the ModSecurity web-based application firewall is enabled on your Apache HTTP
server:
# ls /etc/httpd/modsecurity.d/activated_rules/
17
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
...
REQUEST-921-PROTOCOL-ATTACK.conf
REQUEST-930-APPLICATION-ATTACK-LFI.conf
...
Additional resources
Prerequisites
Procedure
1. Open the /etc/httpd/conf.d/mod_security.conf file in a text editor of your choice, for example:
# vi /etc/httpd/conf.d/mod_security.conf
2. Add the following example rule after the line starting with SecRuleEngine On:
The previous rule forbids the use of resources to the user if the data parameter contains the
evil string.
Verification
18
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
3. Request test.html without malicious data in the GET variable of the HTTP request:
$ curl http://localhost/test.html?data=good
mod_security test
4. Request test.html with malicious data in the GET variable of the HTTP request:
$ curl localhost/test.html?data=xxxevilxxx
5. Check the /var/log/httpd/error_log file, and locate the log entry about denying access with the
param data containing an evil data message:
Additional resources
ModSecurity Wiki
Performance tuning
Authentication settings
Modules
Content caching
Security tips
After installing the manual, you can display it using a web browser.
Prerequisites
19
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
Procedure
2. Optional: By default, all clients connecting to the Apache HTTP Server can display the manual.
To restrict access to a specific IP range, such as the 192.0.2.0/24 subnet, edit the
/etc/httpd/conf.d/manual.conf file and add the Require ip 192.0.2.0/24 setting to the
<Directory "/usr/share/httpd/manual"> directive:
<Directory "/usr/share/httpd/manual">
...
**Require ip 192.0.2.0/24**
...
</Directory>
Verification steps
1. To display the Apache HTTP Server manual, connect with a web browser to
http://host_name_or_IP_address/manual/
Prerequisites
Procedure
1. Search for the module name in the configuration files in the /etc/httpd/conf.modules.d/
directory:
2. Edit the configuration file in which the module name was found, and uncomment the
20
CHAPTER 1. SETTING UP THE APACHE HTTP WEB SERVER
2. Edit the configuration file in which the module name was found, and uncomment the
LoadModule directive of the module:
3. If the module was not found, for example, because a RHEL package does not provide the
module, create a configuration file, such as /etc/httpd/conf.modules.d/30-example.conf with
the following directive:
Prerequisites
Procedure
# apxs -i -a -c module_name.c
Verification steps
Load the module the same way as described in Loading a DSO module .
21
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
Kerberos authentication on an Apache HTTP server: Using GSS-Proxy for Apache httpd
operation. Using Kerberos is an alternative way to enforce client authorization on an Apache
HTTP Server.
22
CHAPTER 2. SETTING UP AND CONFIGURING NGINX
Web server
Reverse proxy
Load balancer
Using the default configuration, NGINX runs as a web server on port 80 and provides content from the
/usr/share/nginx/html/ directory.
Prerequisites
RHEL 9 is installed.
Procedure
To install NGINX 1.20 as the initial version of this Application Stream from an RPM package:
NOTE
23
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
2. Open the ports on which NGINX should provide its service in the firewall. For example, to open
the default ports for HTTP (port 80) and HTTPS (port 443) in firewalld, enter:
3. Enable the nginx service to start automatically when the system boots:
If you do not want to use the default configuration, skip this step, and configure NGINX
accordingly before you start the service.
Verification steps
1. Use the dnf utility to verify that the nginx package is installed.
2. Ensure that the ports on which NGINX should provide its service are opened in the firewalld:
# firewall-cmd --list-ports
80/tcp 443/tcp
24
CHAPTER 2. SETTING UP AND CONFIGURING NGINX
Additional resources
Securing networks
To serve requests to the example.com domain with content from the /var/www/example.com/
directory
To serve requests to the example.net domain with content from the /var/www/example.net/
directory
To serve all other requests, for example, to the IP address of the server or to other domains
associated with the IP address of the server, with content from the /usr/share/nginx/html/
directory
Prerequisites
NGINX is installed
Clients and the web server resolve the example.com and example.net domain to the IP
address of the web server.
Note that you must manually add these entries to your DNS server.
Procedure
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
}
The listen directive define which IP address and ports the service listens. In this case,
NGINX listens on port 80 on both all IPv4 and IPv6 addresses. The default_server
parameter indicates that NGINX uses this server block as the default for requests
matching the IP addresses and ports.
The server_name parameter defines the host names for which this server block is
25
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
The server_name parameter defines the host names for which this server block is
responsible. Setting server_name to _ configures NGINX to accept any host name for
this server block.
The root directive sets the path to the web content for this server block.
b. Append a similar server block for the example.com domain to the http block:
server {
server_name example.com;
root /var/www/example.com/;
access_log /var/log/nginx/example.com/access.log;
error_log /var/log/nginx/example.com/error.log;
}
The access_log directive defines a separate access log file for this domain.
The error_log directive defines a separate error log file for this domain.
c. Append a similar server block for the example.net domain to the http block:
server {
server_name example.net;
root /var/www/example.net/;
access_log /var/log/nginx/example.net/access.log;
error_log /var/log/nginx/example.net/error.log;
}
# mkdir -p /var/www/example.com/
# mkdir -p /var/www/example.net/
Note that you must install the policycoreutils-python-utils package to run the restorecon
commands.
# mkdir /var/log/nginx/example.com/
# mkdir /var/log/nginx/example.net/
26
CHAPTER 2. SETTING UP AND CONFIGURING NGINX
Verification steps
2. Use a browser and connect to http://example.com. The web server shows the example content
from the /var/www/example.com/index.html file.
3. Use a browser and connect to http://example.net. The web server shows the example content
from the /var/www/example.net/index.html file.
4. Use a browser and connect to http://IP_address_of_the_server. The web server shows the
example content from the /usr/share/nginx/html/index.html file.
Prerequisites
NGINX is installed.
The TLS certificate is stored in the /etc/pki/tls/certs/example.com.crt file. If you use a different
path, adapt the corresponding steps of the procedure.
The CA certificate has been appended to the TLS certificate file of the server.
Clients and the web server resolve the host name of the server to the IP address of the web
server.
Procedure
1. Edit the /etc/nginx/nginx.conf file, and add the following server block to the http block in the
configuration:
server {
listen 443 ssl;
server_name example.com;
root /usr/share/nginx/html;
ssl_certificate /etc/pki/tls/certs/example.com.crt;
ssl_certificate_key /etc/pki/tls/private/example.com.key;
}
2. For security reasons, configure that only the root user can access the private key file:
27
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
WARNING
Verification steps
Additional resources
This procedure explains how to forward traffic to the /example directory on the web server to the URL
https://example.com.
Prerequisites
Procedure
1. Edit the /etc/nginx/nginx.conf file and add the following settings to the server block that
should provide the reverse proxy:
location /example {
proxy_pass https://example.com;
}
The location block defines that NGINX passes all requests in the /example directory to
28
CHAPTER 2. SETTING UP AND CONFIGURING NGINX
The location block defines that NGINX passes all requests in the /example directory to
https://example.com.
# setsebool -P httpd_can_network_connect 1
Verification steps
Prerequisites
Procedure
http {
upstream backend {
least_conn;
server server1.example.com;
server server2.example.com;
server server3.example.com backup;
}
server {
location / {
proxy_pass http://backend;
}
}
}
The least_conn directive in the host group named backend defines that NGINX sends
requests to server1.example.com or server2.example.com, depending on which host has the
least number of active connections. NGINX uses server3.example.com only as a backup in case
that the other two hosts are not available.
With the proxy_pass directive set to http://backend, NGINX acts as a reverse proxy and uses
the backend host group to distribute requests based on the settings of this group.
29
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
No method to use round robin and distribute requests evenly across servers.
ip_hash to send requests from one client address to the same server based on a hash
calculated from the first three octets of the IPv4 address or the whole IPv6 address of the
client.
hash to determine the server based on a user-defined key, which can be a string, a variable,
or a combination of both. The consistent parameter configures that NGINX distributes
requests across all servers based on the user-defined hashed key value.
30
CHAPTER 3. CONFIGURING THE SQUID CACHING PROXY SERVER
Prerequisites
The procedure assumes that the /etc/squid/squid.conf file is as provided by the squid
package. If you edited this file before, remove the file and reinstall the package.
Procedure
a. Adapt the localnet access control lists (ACL) to match the IP ranges that should be allowed
to use the proxy:
By default, the /etc/squid/squid.conf file contains the http_access allow localnet rule
that allows using the proxy from all IP ranges specified in localnet ACLs. Note that you must
specify all localnet ACLs before the http_access allow localnet rule.
IMPORTANT
Remove all existing acl localnet entries that do not match your environment.
b. The following ACL exists in the default configuration and defines 443 as a port that uses the
HTTPS protocol:
If users should be able to use the HTTPS protocol also on other ports, add an ACL for each
of these port:
c. Update the list of acl Safe_ports rules to configure to which ports Squid can establish a
connection. For example, to configure that clients using the proxy can only access
31
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
resources on port 21 (FTP), 80 (HTTP), and 443 (HTTPS), keep only the following acl
Safe_ports statements in the configuration:
By default, the configuration contains the http_access deny !Safe_ports rule that defines
access denial to ports that are not defined in Safe_ports ACLs.
d. Configure the cache type, the path to the cache directory, the cache size, and further cache
type-specific settings in the cache_dir parameter:
3. If you set a different cache directory than /var/spool/squid/ in the cache_dir parameter:
# mkdir -p path_to_cache_directory
c. If you run SELinux in enforcing mode, set the squid_cache_t context for the cache
directory:
If the semanage utility is not available on your system, install the policycoreutils-python-
utils package.
32
CHAPTER 3. CONFIGURING THE SQUID CACHING PROXY SERVER
Verification steps
To verify that the proxy works correctly, download a web page using the curl utility:
If curl does not display any error and the index.html file was downloaded to the current directory, the
proxy works.
Prerequisites
The procedure assumes that the /etc/squid/squid.conf file is as provided by the squid
package. If you edited this file before, remove the file and reinstall the package.
Procedure
a. To configure the basic_ldap_auth helper utility, add the following configuration entry to
the top of /etc/squid/squid.conf:
The following describes the parameters passed to the basic_ldap_auth helper utility in the
example above:
-W path_to_password_file sets the path to the file that contains the password of the
proxy service user. Using a password file prevents that the password is visible in the
operating system’s process list.
-f LDAP_filter specifies the LDAP search filter. Squid replaces the %s variable with the
33
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
-f LDAP_filter specifies the LDAP search filter. Squid replaces the %s variable with the
user name provided by the authenticating user.
The (&(objectClass=person)(uid=%s)) filter in the example defines that the user
name must match the value set in the uid attribute and that the directory entry contains
the person object class.
-ZZ enforces a TLS-encrypted connection over the LDAP protocol using the
STARTTLS command. Omit the -ZZ in the following situations:
The -H LDAP_URL parameter specifies the protocol, the host name or IP address, and
the port of the LDAP server in URL format.
b. Add the following ACL and rule to configure that Squid allows only authenticated users to
use the proxy:
IMPORTANT
c. Remove the following rule to disable bypassing the proxy authentication from IP ranges
specified in localnet ACLs:
d. The following ACL exists in the default configuration and defines 443 as a port that uses the
HTTPS protocol:
If users should be able to use the HTTPS protocol also on other ports, add an ACL for each
of these port:
e. Update the list of acl Safe_ports rules to configure to which ports Squid can establish a
connection. For example, to configure that clients using the proxy can only access
resources on port 21 (FTP), 80 (HTTP), and 443 (HTTPS), keep only the following acl
Safe_ports statements in the configuration:
By default, the configuration contains the http_access deny !Safe_ports rule that defines
access denial to ports that are not defined in Safe_ports ACLs.
f. Configure the cache type, the path to the cache directory, the cache size, and further cache
34
CHAPTER 3. CONFIGURING THE SQUID CACHING PROXY SERVER
f. Configure the cache type, the path to the cache directory, the cache size, and further cache
type-specific settings in the cache_dir parameter:
3. If you set a different cache directory than /var/spool/squid/ in the cache_dir parameter:
# mkdir -p path_to_cache_directory
c. If you run SELinux in enforcing mode, set the squid_cache_t context for the cache
directory:
If the semanage utility is not available on your system, install the policycoreutils-python-
utils package.
4. Store the password of the LDAP service user in the /etc/squid/ldap_password file, and set
appropriate permissions for the file:
Verification steps
35
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
To verify that the proxy works correctly, download a web page using the curl utility:
# curl -O -L "https://www.redhat.com/index.html" -x
"user_name:[email protected]:3128"
If curl does not display any error and the index.html file was downloaded to the current directory, the
proxy works.
Troubleshooting steps
To verify that the helper utility works correctly:
1. Manually start the helper utility with the same settings you used in the auth_param parameter:
# /usr/lib64/squid/basic_ldap_auth -b "cn=users,cn=accounts,dc=example,dc=com" -D
"uid=proxy_user,cn=users,cn=accounts,dc=example,dc=com" -W
/etc/squid/ldap_password -f "(&(objectClass=person)(uid=%s))" -ZZ -H
ldap://ldap_server.example.com:389
user_name password
Prerequisites
The procedure assumes that the /etc/squid/squid.conf file is as provided by the squid
package. If you edited this file before, remove the file and reinstall the package.
The server on which you want to install Squid is a member of the AD domain.
Procedure
# kinit [email protected]
# export KRB5_KTNAME=FILE:/etc/squid/HTTP.keytab
# net ads keytab CREATE -U administrator
36
CHAPTER 3. CONFIGURING THE SQUID CACHING PROXY SERVER
6. Optionally, verify that the keytab file contains the HTTP service principal for the fully-qualified
domain name (FQDN) of the proxy server:
klist -k /etc/squid/HTTP.keytab
Keytab name: FILE:/etc/squid/HTTP.keytab
KVNO Principal
---- ---------------------------------------------------
...
2 HTTP/[email protected]
...
-k file sets the path to the key tab file. Note that the squid user must have read
permissions on this file.
b. Add the following ACL and rule to configure that Squid allows only authenticated users to
use the proxy:
IMPORTANT
c. Remove the following rule to disable bypassing the proxy authentication from IP ranges
37
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
c. Remove the following rule to disable bypassing the proxy authentication from IP ranges
specified in localnet ACLs:
d. The following ACL exists in the default configuration and defines 443 as a port that uses the
HTTPS protocol:
If users should be able to use the HTTPS protocol also on other ports, add an ACL for each
of these port:
e. Update the list of acl Safe_ports rules to configure to which ports Squid can establish a
connection. For example, to configure that clients using the proxy can only access
resources on port 21 (FTP), 80 (HTTP), and 443 (HTTPS), keep only the following acl
Safe_ports statements in the configuration:
By default, the configuration contains the http_access deny !Safe_ports rule that defines
access denial to ports that are not defined in Safe_ports ACLs.
f. Configure the cache type, the path to the cache directory, the cache size, and further cache
type-specific settings in the cache_dir parameter:
8. If you set a different cache directory than /var/spool/squid/ in the cache_dir parameter:
# mkdir -p path_to_cache_directory
38
CHAPTER 3. CONFIGURING THE SQUID CACHING PROXY SERVER
c. If you run SELinux in enforcing mode, set the squid_cache_t context for the cache
directory:
If the semanage utility is not available on your system, install the policycoreutils-python-
utils package.
Verification steps
To verify that the proxy works correctly, download a web page using the curl utility:
If curl does not display any error and the index.html file exists in the current directory, the proxy works.
Troubleshooting steps
To manually test Kerberos authentication:
# kinit [email protected]
# klist
# /usr/lib64/squid/negotiate_kerberos_auth_test proxy.ad.example.com
Token: YIIFtAYGKwYBBQUCoIIFqDC...
Prerequisites
39
Red Hat Enterprise Linux 9 Deploying web servers and reverse proxies
Procedure
IMPORTANT
Add these entries before the first http_access allow statement that allows
access to users or clients.
2. Create the /etc/squid/domain_deny_list.txt file and add the domains you want to block. For
example, to block access to example.com including subdomains and to block example.net,
add:
.example.com
example.net
IMPORTANT
Prerequisites
Procedure
To set the port on which the Squid service listens, set the port number in the http_port
parameter. For example, to set the port to 8080, set:
http_port 8080
To configure on which IP address the Squid service listens, set the IP address and port
40
CHAPTER 3. CONFIGURING THE SQUID CACHING PROXY SERVER
To configure on which IP address the Squid service listens, set the IP address and port
number in the http_port parameter. For example, to configure that Squid listens only on the
192.0.2.1 IP address on port 3128, set:
http_port 192.0.2.1:3128
Add multiple http_port parameters to the configuration file to configure that Squid listens
on multiple ports and IP addresses:
http_port 192.0.2.1:3128
http_port 192.0.2.1:8080
2. If you configured that Squid uses a different port as the default (3128):
b. If you run SELinux in enforcing mode, assign the port to the squid_port_t port type
definition:
If the semanage utility is not available on your system, install the policycoreutils-python-
utils package.
41