我已将我的 Ubuntu 服务器迁移到 AWS EC2 实例。问题是 Apache 服务已启动并正在运行,但当我输入“server-IP/phppage.php”时,没有任何内容显示。过了一会儿,显示“连接已超时”错误。端口 80 正在监听,我使用的是 Ubuntu 18.04.4 LTS。
yello-pc123:~$ sudo netstat -anp | grep 80
tcp6 0 0 :::80 :::* LISTEN 912/apache2
unix 3 [ ] STREAM CONNECTED 20739 809/python3
unix 3 [ ] STREAM CONNECTED 20380 1/init /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 18058 809/python3
unix 3 [ ] STREAM CONNECTED 14606 480/lvmetad
unix 3 [ ] STREAM CONNECTED 18059 1/init /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 20269 803/systemd-logind
unix 2 [ ] DGRAM 20150 803/systemd-logind
unix 3 [ ] STREAM CONNECTED 17898 803/systemd-logind
由于我没有服务器的 GUI 访问权限,$curl localhost
因此我
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Apache2 Debian Default Page: It works</title>
<style type="text/css" media="screen">
编辑:我已将 listen 指令更改为Listen 0.0.0.0:80
,但仍然没有成功。 的新输出$sudo netstat -anp | grep 80
是
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10236/apache2
unix 3 [ ] STREAM CONNECTED 20739 809/python3
unix 3 [ ] STREAM CONNECTED 20380 1/init /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 18058 809/python3
unix 3 [ ] STREAM CONNECTED 14606 480/lvmetad
unix 3 [ ] STREAM CONNECTED 18059 1/init /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 20269 803/systemd-logind
unix 2 [ ] DGRAM 20150 803/systemd-logind
unix 3 [ ] STREAM CONNECTED 17898 803/systemd-logind
编辑
yello-pc123:~$ sudo cat /var/log/apache2/error.log
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/sqlsrv.so' - /usr/lib/php/20131226/sqlsrv.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/pdo_sqlsrv.so' - /usr/lib/php/20131226/pdo_sqlsrv.so: cannot open shared object file: No such file or directory in Unknown on line 0
[Sun May 10 06:25:01.830025 2020] [mpm_prefork:notice] [pid 2247] AH00163: Apache/2.4.43 (Ubuntu) configured -- resuming normal operations
[Sun May 10 06:25:01.830043 2020] [core:notice] [pid 2247] AH00094: Command line: '/usr/sbin/apache2'
[Sun May 10 11:24:34.076951 2020] [mpm_prefork:notice] [pid 2247] AH00169: caught SIGTERM, shutting down
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/sqlsrv.so' - /usr/lib/php/20131226/sqlsrv.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/pdo_sqlsrv.so' - /usr/lib/php/20131226/pdo_sqlsrv.so: cannot open shared object file: No such file or directory in Unknown on line 0
[Sun May 10 11:25:16.357649 2020] [mpm_prefork:notice] [pid 895] AH00163: Apache/2.4.43 (Ubuntu) configured -- resuming normal operations
[Sun May 10 11:25:16.357720 2020] [core:notice] [pid 895] AH00094: Command line: '/usr/sbin/apache2'
[Sun May 10 11:39:58.714752 2020] [mpm_prefork:notice] [pid 895] AH00169: caught SIGTERM, shutting down
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/sqlsrv.so' - /usr/lib/php/20131226/sqlsrv.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/pdo_sqlsrv.so' - /usr/lib/php/20131226/pdo_sqlsrv.so: cannot open shared object file: No such file or directory in Unknown on line 0
[Sun May 10 11:39:58.845545 2020] [mpm_prefork:notice] [pid 1679] AH00163: Apache/2.4.43 (Ubuntu) configured -- resuming normal operations
[Sun May 10 11:39:58.845609 2020] [core:notice] [pid 1679] AH00094: Command line: '/usr/sbin/apache2'
答案1
经过三天的努力,我终于找到了答案。我留下答案以供将来参考,如果其他人遇到同样的问题,他可以使用这个。因为本地主机上的一切工作正常。问题是,由于 VM 位于 EC2 实例上,并且 AWS 默认阻止来自端口 80 的 HTTP 流量。因此,您必须在安全组中为传入流量添加入站规则。此链接解释了详细信息https://aws.amazon.com/premiumsupport/knowledge-center/connect-http-https-ec2/