在Ubuntu VM上无法访问Apache服务器

我是linux / ubuntu的新手,但是我想在Ubuntu VM上设置一个Apache web服务器。 我在亚马逊AWS上创build了一个虚拟机,安装了apache。 但现在我无法通过浏览器访问它。 我不知道如果Apache服务器正常运行或者如果有任何端口被阻止。

我检查了Apache的版本。 似乎与“apache -version”安装,它显示我一个有效的版本和安装date。

我检查打开的端口。 看起来apache正在某些端口(3609,3614,3615)上监听,而不是在80端口上? 这可能是问题吗? 如何解决?

编辑1:实际上我想添加一些sceenshots,但是我不能用低于10的报酬来做到这一点。

编辑2:

  • “sudo /etc/init.d/apache2 status”告诉我它正在运行
  • error.log也看起来不错。 它只说:“Apache / 2.2.22(Ubuntu)configuration – 恢复正常操作

编辑3:从服务器可以访问本地主机。 所以这似乎是一个防火墙/连接问题。 但奇怪的是:我可以通过外部的telnet ping服务器ip上的端口80。

编辑4:我可以从其他亚马逊虚拟机到我的networking服务器! 那么这是什么意思:那么这对亚马逊的安全组织来说是一个问题呢? 为了testing目的,我在安全组中开了很多端口: 在这里输入图像说明

apache2.conf如下所示:

# # The accept serialization lock file MUST BE STORED ON A LOCAL DISK. # LockFile ${APACHE_LOCK_DIR}/accept.lock # # PidFile: The file in which the server should record its process # identification number when it starts. # This needs to be set in /etc/apache2/envvars # PidFile ${APACHE_PID_FILE} # # Timeout: The number of seconds before receives and sends time out. # Timeout 300 # # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 100 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 5 ## ## Server-Pool Size Regulation (MPM specific) ## # prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 0 </IfModule> # worker MPM # StartServers: initial number of server processes to start # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadLimit: ThreadsPerChild can be changed to this maximum value during a # graceful restart. ThreadLimit can only be changed by stopping # and starting Apache. # ThreadsPerChild: constant number of worker threads in each server process # MaxClients: maximum number of simultaneous client connections # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_worker_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 150 MaxRequestsPerChild 0 </IfModule> # event MPM # StartServers: initial number of server processes to start # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadsPerChild: constant number of worker threads in each server process # MaxClients: maximum number of simultaneous client connections # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule mpm_event_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 150 MaxRequestsPerChild 0 </IfModule> # These need to be set in /etc/apache2/envvars User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} # # AccessFileName: The name of the file to look for in each directory # for additional configuration directives. See also the AllowOverride # directive. # AccessFileName .htaccess # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <Files ~ "^\.ht"> Order allow,deny Deny from all Satisfy all </Files> # # DefaultType is the default MIME type the server will use for a document # if it cannot otherwise determine one, such as from filename extensions. # If your server contains mostly text or HTML documents, "text/plain" is # a good value. If most of your content is binary, such as applications # or images, you may want to use "application/octet-stream" instead to # keep browsers from trying to display binary files as though they are # text. # # It is also possible to omit any default MIME type and let the # client's browser guess an appropriate action instead. Typically the # browser will decide based on the file's extension then. In cases # where no good assumption can be made, letting the default MIME type # unset is suggested instead of forcing the browser to accept # incorrect metadata. # DefaultType None # # HostnameLookups: Log the names of clients or just their IP addresses # eg, www.apache.org (on) or 204.62.129.132 (off). # The default is off because it'd be overall better for the net if people # had to knowingly turn this feature on, since enabling it means that # each client request will result in AT LEAST one lookup request to the # nameserver. # HostnameLookups Off # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here. # ErrorLog ${APACHE_LOG_DIR}/error.log # # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn # Include module configuration: Include mods-enabled/*.load Include mods-enabled/*.conf # Include list of ports to listen on and which to use for name based vhosts Include ports.conf # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i # LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %O" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent # Include of directories ignores editors' and dpkg's backup files, # see the comments above for details. # Include generic snippets of statements Include conf.d/ # Include the virtual host configurations: Include sites-enabled/ 

ports.conf看起来像这样:

 NameVirtualHost *:80 Listen 80 <IfModule mod_ssl.c> # If you add NameVirtualHost *:443 here, you will also have to change # the VirtualHost statement in /etc/apache2/sites-available/default-ssl # to <VirtualHost *:443> # Server Name Indication for SSL named virtual hosts is currently not # supported by MSIE on Windows XP. Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule> 

编辑5:

如果我尝试访问networking服务器,则会收到以下消息:“网站不可用:” 在这里输入图像说明

编辑6:

“etc / apache2 / sites-available / default”看起来像这样:

 <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> 

编辑7:

其实我不能ping我的主机,只有端口80上的telnet工作。

编辑8:

本地telnet“localhost 80”和“netstat -l”结果:

“远程login”:

在这里输入图像说明

“netstat -l”: 在这里输入图像说明

编辑9:

因为看起来,networking服务器正在监听ip6 ip,所以我改变了我的“ports.conf”,并添加了如“Christoph Eicke”build议的条目“Listen YOUR_AWS_IP:80”。 现在networking服务器似乎听ip4的地址。 但我仍然无法访问networking服务器。

在这里输入图像说明

在你的netstat -l命令中,我没有看到在端口80上监听IPv4的任何东西。 你的networking服务器不会监听IPv6接口。

在本地可以连接到它是有意义的,因为您的工具可能已经可以说IPv6了,localhost通过/etc/hostsparsing为有效的IPv6 IP。 但是你的networking可能不会说IPv6。

从你的问题来看,这不是100%显而易见的,所以我可以问你安装Apache之后是否启动了Apache? “sudo /etc/init.d/apache2 status”会告诉你它是否真的在运行。

我要检查的下一个地方是Apache的日志文件,你可以在/ var / log / apache2 /下find它。

编辑 :既然这两个检查出来,你能够从服务器本地看到Apache? 运行服务器上的Web浏览器,将其指向http://localhost并查看会发生什么情况。

编辑2 :如果Apache正在运行且没有防火墙规则,那么现在是时候查看Apache的configuration本身,以获得允许本地连接但不允许远程连接的指令。 各种configuration文件应该在/ etc / apache2中; 看看“拒绝所有”或“允许<地址范围>”这样的行。

可能有一组标准的安全组和一个EC2实例,但请记住,您可以创build多个安全组和多个EC2实例,因此:

您必须将安全组分配给EC2实例。

转到AWS网站 – > EC2 – >实例 – >select你的实例 – >动作button – >networking/更改安全组 – >在这里你可以assingn,在大多数情况下只是检查'默认'并保存。

我有困难连接到端口8080.我安装了Apache2的sudo apt-get安装Apache2

并能够在8080端口上收听。默认情况下,EC2上没有安装Apache2。