A memorandum when Apache was installed on CentOS of VitrualBox.
It is assumed that you have made the basic settings of CentOS in the following articles. https://qiita.com/kazu_kazu/items/6e8dd09a5b0f641c3bf3
MacBook Pro (macOS Catalina version 10.15.6) VirtualBox 6.1.14 CentOS 8.2 Apache 2.4.37
Install according to the following article. WEB ARCH LABO "Procedures for installing Apache httpd 2.4 on CentOS 7 with yum" https://weblabo.oscasierra.net/apache-installing-apache24-yum-centos7-1/
Install with yum, not from source. First, display the package information to check the version to install.
[test1@www ~]$ yum info httpd
CentOS-8 - AppStream 4.8 kB/s | 4.3 kB 00:00
CentOS-8 - Base 11 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 4.4 kB/s | 1.5 kB 00:00
Available packages
name: httpd
version: 2.4.37
release: 21.module_el8.2.0+494+1df74eae
Arch : x86_64
size: 1.7 M
Source: httpd-2.4.37-21.module_el8.2.0+494+1df74eae.src.rpm
Repository: AppStream
Overview: Apache HTTP Server
URL : https://httpd.apache.org/
license: ASL 2.0
Explanation: The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
Next is installation.
[test1@www ~]$ sudo yum -y install httpd
[test1@www ~]$ httpd -v
Server version: Apache/2.4.37 (centos)
Server built: Sep 15 2020 15:41:16
[test1@www ~]$ systemctl start httpd.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
'httpd.service'Authentication is required to start.
Authenticating as:
Password:
==== AUTHENTICATION COMPLETE ====
[test1@www ~]$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
Active: active (running) since Sat 2020-10-24 16:57:35 JST; 45s ago
Docs: man:httpd.service(8)
Main PID: 33732 (httpd)
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 4876)
Memory: 20.9M
CGroup: /system.slice/httpd.service
├─33732 /usr/sbin/httpd -DFOREGROUND
├─33737 /usr/sbin/httpd -DFOREGROUND
├─33738 /usr/sbin/httpd -DFOREGROUND
├─33739 /usr/sbin/httpd -DFOREGROUND
└─33740 /usr/sbin/httpd -DFOREGROUND
Access the web server by entering http: // (IP address of the guest who installed Apache)
in the host browser.
Success if the following screen is displayed.
Web server stopped.
[test1@www ~]$ systemctl stop httpd.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
'httpd.service'Authentication is required to stop.
Authenticating as:
Password:
==== AUTHENTICATION COMPLETE ====
The current virtual machine network settings are NAT for adapter 1 and host-only adapter for adapter 2. The status of the host and guest IP addresses is as follows.
OS | Interface name | IPv4 address |
---|---|---|
The guests | enp0s3(NAT) | 10.0.2.15 |
The guests | enp0s8(Host-only adapter) | 192.168.56.10 |
host | en0 | 192.168.0.4 |
host | vboxnet0 (host-only adapter) | 192.168.56.1 |
Access to the Web server from the host to the guest can be easily realized by using the host-only adapter, but access within the same LAN other than the host (access from your smartphone to the guest, etc.) will be accessed via NAT. In order to access guests with NAT, you need to configure port forwarding (NAT is set to be inaccessible from the host and other computers by default).
From the VM settings, go to Network → Adapter 1 → Advanced → Port Forwarding and set as follows (the name should be appropriate, and the host port should be a port other than the well-known port and not used by the host).
Allow http on the guest firewall. I don't know why the host-only adapter was able to connect without permission.
[root@www ~]# firewall-cmd --add-service=http --permanent
success
[root@www ~]# firewall-cmd --reload
success
[root@www ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:
services: cockpit dhcpv6-client http
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
After starting the web server as a guest, check the connection on the smartphone (the following picture is a picture of the browser of the host PC, but the connection was also possible on the smartphone).
The IPv4 address entered in the browser is not that of the guest, but the IPv4 address of the host and the port number set in port forwarding are entered (as mentioned above, NAT cannot directly access the guest, so connect via the host).
For NAT and port forwarding, I referred to the following user manual. http://download.virtualbox.org/virtualbox/UserManual.pdf
Recommended Posts