关于apache2的443端口进行转发遇到的问题

1.问题,我目前有多个docker容器,那么假如都需要用80端口访问,当80:80进行映射,导致这个80端口被占用,因此在宿主机,我装了一个apache2进行端口转发。

过程如下:外网对于80端口,我通过宿主机的apache2转发至8880端口,然后通过dokcer的端口映射8880:80访问容易内部的服务,至此,并未出现问题。但是当外网访问443端口,即https访问,页面报错400,检查了很久也没找到原因,求助。

宿主机的配置如下:

<VirtualHost *:80>
    # 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.liqunwulian.com
    ServerName www.steering.ai

    ServerAdmin admin@steering.ai
    #DocumentRoot /var/www/steering.ai
        
        #off表示开启反向代理,on表示开启正向代理
        ProxyRequests Off
        ProxyMaxForwards 100
        ProxyPreserveHost On
        #这里表示要将现在这个虚拟主机跳转到本机的8800端口
        ProxyPass / http://127.0.0.1:8880/ timeout=600 Keepalive=On
        ProxyPassReverse / http://127.0.0.1:8880/ timeout=600

        <Proxy *>
            Order Deny,Allow
            Allow from all
        </Proxy>

    # 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>

<VirtualHost *:443>
    # 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.steering.ai
    #SSLEngine on
    #SSLCertificateFile "/etc/steering.ai/STAR_steering_ai.crt"
        #SSLCertificateKeyFile "/etc/steering.ai/STAR_steering_ai.key"
    
    ServerAdmin admin@steering.ai
    #DocumentRoot /var/www/steering.ai
        
        #off表示开启反向代理,on表示开启正向代理
        ProxyRequests Off
        ProxyMaxForwards 100
        ProxyPreserveHost On
        #这里表示要将现在这个虚拟主机跳转到本机的4000端口
        ProxyPass / http://127.0.0.1:8883/ timeout=600 Keepalive=On
        ProxyPassReverse / http://127.0.0.1:8883/ timeout=600

        <Proxy *>
            Order Deny,Allow
            Allow from all
        </Proxy>

    # 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>

外网访问80端口,转发到本地的8880然后再映射给docker,便可以访问。但是这个443端口,映射确报400错误,求助!!

阅读 5.4k
1 个回答
    ProxyPass / http://127.0.0.1:8883/ timeout=600 Keepalive=On
    ProxyPassReverse / http://127.0.0.1:8883/ timeout=600

估计问题出现在这, 如果你的docker 8883端口下采用https协议,那也要相应地改成

    ProxyPass / https://127.0.0.1:8883/ timeout=600 Keepalive=On
    ProxyPassReverse / https://127.0.0.1:8883/ timeout=600
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题