首页 > 解决方案 > 尝试为两个不同的端口配置 apache2 Web 服务器

问题描述

我正在 Google Cloud 的 Ubuntu 18.04LTS VM 实例中设置新的 apache2 服务器。我想将它配置为在两个不同的端口上工作。它在端口 80 上正常工作([my ip]:80 正确呈现),但无法在 [my ip]:8087 上加载。

在 vm 上运行 netstat -atn :

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0    448 10.160.0.3:22           74.125.41.97:42740      ESTABLISHED
tcp        0      0 10.160.0.3:49834        169.254.169.254:80      ESTABLISHED
tcp        0      0 10.160.0.3:49836        169.254.169.254:80      ESTABLISHED
tcp        0      0 10.160.0.3:49832        169.254.169.254:80      ESTABLISHED
tcp        0      0 10.160.0.3:49830        169.254.169.254:80      CLOSE_WAIT 
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 :::8087                 :::*                    LISTEN 

我还编辑了 VPC 网络 -> 防火墙规则:

Name    firewall-8087
Type    Ingress
Targets Apply to all
Filters IP ranges: 0.0.0.0/0
Protocols / port   tcp:8087  udp:8087
Action  Allow
Priority  1000  
Network   default

我的 /etc/apache2/ports.conf 文件:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
Listen 8087

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

我的 /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80 *:8087>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

这是我编辑的仅有的两个文件。

标签: apacheservergoogle-cloud-platformportgcloud

解决方案


推荐阅读