1

I migrated my server OS from CentOS 7 to CentOS 8 stream recently with standard installation options. Now I'm facing an error on the HTTP/S server accessing.

Assuming you are running a http server on port 80 or 443. For example using python module http.server:

$> sudo python3 -m http.server -b xxx.xxx.xxx.xxx 80[or 443]

Here, xxx.xxx.xxx.xxx represent the public IP, and the http.server can be replaced with any web server such as Apache, Nginx or Podman container.

To avoid the influence from firewall, I disabled the firewalld.service with:

$> sudo systemctl stop firewalld.service

Furthermore, before running the http server, I have confirmed that no other process listening on port 80 or 443 by:

$> netstat -lnt | grep 80[or 443]
$> # nothing returned

So, normally when some one access this server, for example using:

curl xxx.xxx.xxx.xxx

It should be responded with some content from the running server, e.g. the folders and files under the current dir.

But in my case, this command returns "404 page not found" on port 80 and "Client sent an HTTP request to an HTTPS server." on port 443 in plain text, respectively. This error only occurs on port 80 and 443 with public IP access, that means the following action works.

$> curl localhost

In fact, it doesn't matter whether there is a running http server. Seem like there is an invisible HTTP server and running with higher priority.

I tried a lot to handle this error and found that when the status of firewalld.service changed, e.g stop/start/restart the firewalld.service, there will be a short time (about 10 sec) to access the running server normally after the change.

All running services all listed as below:

liuchang@xenonpy ~ ❯❯❯ systemctl --type=service --state=running
UNIT                     LOAD   ACTIVE SUB     DESCRIPTION
accounts-daemon.service  loaded active running Accounts Service
atd.service              loaded active running Job spooling tools
auditd.service           loaded active running Security Auditing Service
avahi-daemon.service     loaded active running Avahi mDNS/DNS-SD Stack
chronyd.service          loaded active running NTP client/server
colord.service           loaded active running Manage, Install and Generate Color Profiles
crond.service            loaded active running Command Scheduler
cups.service             loaded active running CUPS Scheduler
dbus.service             loaded active running D-Bus System Message Bus
firewalld.service        loaded active running firewalld - dynamic firewall daemon
gdm.service              loaded active running GNOME Display Manager
gssproxy.service         loaded active running GSSAPI Proxy Daemon
irqbalance.service       loaded active running irqbalance daemon
k3s.service              loaded active running Lightweight Kubernetes
ksmtuned.service         loaded active running Kernel Samepage Merging (KSM) Tuning Daemon
libstoragemgmt.service   loaded active running libstoragemgmt plug-in server daemon
mcelog.service           loaded active running Machine Check Exception Logging Daemon
ModemManager.service     loaded active running Modem Manager
NetworkManager.service   loaded active running Network Manager
packagekit.service       loaded active running PackageKit Daemon
polkit.service           loaded active running Authorization Manager
rdma-ndd.service         loaded active running RDMA Node Description Daemon
rhsmcertd.service        loaded active running Enable periodic update of entitlement certificates.
rngd.service             loaded active running Hardware RNG Entropy Gatherer Daemon
rpcbind.service          loaded active running RPC Bind
rsyslog.service          loaded active running System Logging Service
rtkit-daemon.service     loaded active running RealtimeKit Scheduling Policy Service
smartd.service           loaded active running Self Monitoring and Reporting Technology (SMART) Daemon
sshd.service             loaded active running OpenSSH server daemon
sssd.service             loaded active running System Security Services Daemon
systemd-journald.service loaded active running Journal Service
systemd-logind.service   loaded active running Login Service
systemd-machined.service loaded active running Virtual Machine and Container Registration Service
systemd-udevd.service    loaded active running udev Kernel Device Manager
tuned.service            loaded active running Dynamic System Tuning Daemon
udisks2.service          loaded active running Disk Manager
upower.service           loaded active running Daemon for power management
user@1000.service        loaded active running User Manager for UID 1000
user@42.service          loaded active running User Manager for UID 42
wpa_supplicant.service   loaded active running WPA supplicant

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

40 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

I have no idea about this and hope someone can help me. Thanks in advance!

tsumina
  • 11
  • 3

1 Answers1

0

You are running an http server without any other context, so basically it will show you a directory listing of the directory where the command was executed.

Now, if you get a 404, that means that the curl has the index.html attached to it http://..../index.html.

The "right" way to do this is to specify the path for the server to serve, then it will work.

For this, just go to the folder containing the index.html, run the http.server from there and try again, it should display the contents correctly.

On more examples, take a look over here: https://stackabuse.com/serving-files-with-pythons-simplehttpserver-module/

Edit: Something that calls my attention is that it seems like you are running an actual web server, but... not using apache? not nginx?

If you just do that as I told you, the http.server will serve the index.html

enter image description here

enter image description here

Marco
  • 1,172
  • 9
  • 24
  • Thank you for your answer. The python server in the question is just an example, and a running server can be accessed correctly in local, e.g. `curl localhost` will return the real content but `curl xxx.xxx.xxx.xxx` will return **404 page not found**, where xxx.xxx.xxx.xxx denote the public IP. I will update the question to include this info. – tsumina Jan 20 '21 at 22:45
  • Running an actual web server using apache, nginx, Podman, or anything else give the same error. – tsumina Jan 20 '21 at 23:04
  • @tsumina oh ok, that python thing confused me a little. In that case, go and check your httpd.conf and make sure that is was not modified during your upgrade. Make sure the root and document root, you want also to check for changes in your virtual host, you might have a *:80 one, make sure the DirectoryIndex is set up, usually index.html, index.php, both even, and make sure that those actually exist under the DocumentRoot and the permissions are right. Make sure access to the socket is clear, you can either telnet or nc to it, if not, then you have a FW issue instead of web server issue. – Marco Jan 21 '21 at 13:55