Set up reverse proxy to https server with CentOS Linux 8 + Apache mod_ssl


--Install Apache HTTP Server and mod_ssl on CentOS Linux 8 and set up a reverse proxy to the https server


$ cat /etc/centos-release
CentOS Linux release 8.1.1911 (Core)

Apache installation

Install the httpd package with the dnf install command.

$ sudo dnf install httpd

Confirm that it has been installed.

$ dnf list --installed httpd
Installed packages
httpd.x86_64  2.4.37-16.module_el8.1.0+256+ae790463  @AppStream

$ which httpd

$ httpd -v
Server version: Apache/2.4.37 (centos)
Server built:   Dec 23 2019 20:45:34

$ httpd -V
Server version: Apache/2.4.37 (centos)
Server built:   Dec 23 2019 20:45:34
Server's Module Magic Number: 20120211:83
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Enable the systemd httpd service.

$ sudo systemctl enable httpd
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/httpd.service.

Start apache

Start Apache with the systemctl start command.

$ sudo systemctl start httpd

Check the status of Apache.

$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-03-23 21:55:04 JST; 7min ago
     Docs: man:httpd.service(8)

Apache configuration file

There is an Apache configuration file under / etc / httpd /. The main config file is /etc/httpd/conf/httpd.conf, which adds other config files with the Include directive.

$ tree /etc/httpd/
├── conf
│   ├── httpd.conf
│   └── magic
├── conf.d
│   ├── README
│   ├── autoindex.conf
│   ├── userdir.conf
│   └── welcome.conf
├── conf.modules.d
│   ├── 00-base.conf
│   ├── 00-dav.conf
│   ├── 00-lua.conf
│   ├── 00-mpm.conf
│   ├── 00-optional.conf
│   ├── 00-proxy.conf
│   ├── 00-systemd.conf
│   ├── 01-cgi.conf
│   ├── 10-h2.conf
│   ├── 10-proxy_h2.conf
│   └── README
├── logs -> ../../var/log/httpd
├── modules -> ../../usr/lib64/httpd/modules
├── run -> /run/httpd
└── state -> ../../var/lib/httpd

7 directories, 17 files

Install mod_ssl

Install the mod_ssl package with the dnf install command.

$ sudo dnf install mod_ssl

The configuration files ssl.conf and 00-ssl.conf have been added, so add them with the Include directive if necessary.

$ find /etc/httpd | grep ssl

Reverse proxy settings

For example, write the following contents in the configuration file of /etc/httpd/conf/httpd.conf. This time, I put them together in one configuration file without using the Include directive.

ServerRoot "/etc/httpd"

LoadModule authz_core_module modules/
LoadModule mpm_event_module modules/
LoadModule proxy_module modules/
LoadModule proxy_http_module modules/
LoadModule unixd_module modules/
LoadModule ssl_module modules/
LoadModule systemd_module modules/

Listen 80
User apache
Group apache

ErrorLog "logs/error_log"

ProxyRequests Off
SSLProxyEngine On
ProxyPass /foobar/
ProxyPassReverse /foobar/

You can check if the configuration file is correct with the apachectl configtest command.

$ apachectl configtest
Syntax OK

If the settings are correct, restart Apache for the settings to take effect.

$ sudo systemctl restart httpd

Access with curl etc. and check that the response is returned from the server that generated the content.

$ curl --include --silent http://localhost/foobar/ | head
HTTP/1.1 200 OK
Date: Mon, 23 Mar 2020 13:05:09 GMT
Server: Foobar Frontend
Content-Type: text/html;charset=utf-8
Content-Length: 9876

<!DOCTYPE html>
<title>Hello, world.</title>

Reference material

-[Chapter 1 Apache HTTP Web Server Settings Red Hat Enterprise Linux 8 \ | Red Hat Customer Portal]( apache-web-server_deploying-different-types-of-servers) -[1 \ .9 . Mod \ _ssl Module Activation Red Hat Enterprise Linux 8 \ | Red Hat Customer Portal]( deploying_different_types_of_servers / enabling-mod-ssl-module_setting-apache-web-server)

Recommended Posts

Set up reverse proxy to https server with CentOS Linux 8 + Apache mod_ssl
Set up a web server with CentOS7 + Anaconda + Django + Apache
Settings to be made when starting up the linux server centos7
Set up Ubuntu as a Linux cheat sheet and https server
Set up a Samba server with Docker
Send mail with mailx to a dummy SMTP server set up with python.
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Set up a simple HTTPS server in Python 3
Set up a local server with Go-File upload-
Set up golang with goenv on GNU / Linux
Set up a local server with Go-File download-
How to set up a local development server
Reverse proxy with Apache 2.4 on Ubuntu 19.10 Eoan Ermine
Back up from QNAP to Linux with rsync
Set up Docker on Oracle Linux (7.x) with Vagrant
[Part 1] Let's set up a Minecraft server on Linux
How to make an HTTPS server with Go / Gin
[https proxy with squid] How to represent https whitelist with url_regex
[Vagrant] Set up a simple API server with python
ODBC access to SQL Server from Linux with Python
Proxy server with Docker
When it is troublesome to set up an SMTP server locally when sending mail with Python.
How to set up Ubuntu for Windows Subsystem for Linux 2 (WSL2)
Reload the server set up with gunicorn when changing the code
How to start Apache by specifying httpd.conf with systemd (CentOS7, CentOS8)
How to set up and use OMC Log Analytics --Linux version -
Set up a yum repository server on CentOS7 system and refer to it locally and from other servers.
Introduction and usage of Python bottle ・ Try to set up a simple web server with login function