【问题标题】:Redirect Apache Subdomain:80 to 8096将 Apache 子域:80 重定向到 8096
【发布时间】:2017-04-17 22:22:16
【问题描述】:

我有一个域.. sub.example.com,您可以通过端口 80 访问它。

每当用户搜索该域时,我都想得到一个redirect to port 8096,但用户不应该意识到这一点。

有没有人建议如何配置vHost

【问题讨论】:

标签: linux bash apache redirect port


【解决方案1】:

您可以使用重定向到端口 80 到 8096 或使用代理配置。

对我来说代理更好,因为客户端不会在他的网络浏览器中查看您的端口 8096

代理配置示例:

首先确保 apache 在端口 8096 上侦听:

netstat -laputen|grep 8096

如果没有回复,请检查 /etc/apache2/ports.conf 中的监听端口:

听 8096

重启 apache 并在 netstat 中重新检查 LISTEN

service apache2 restart
netstat -laputen|grep 8096

如果不是apache监听8096端口,你只需要创建vhost监听80端口,而不是8096

在 apache2 中启用代理模块:

a2enmod proxy proxy_http

重启apache:

service apache2 restart

创建虚拟主机:

/etc/apache2/sites-available/sub2_example_com.conf

<VirtualHost *:80>
        # Just listen to sub2.example.com, the others sub-domain going to the default Vhost
        ServerName sub2.example.com

        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8096/
        ProxyPassReverse / http://127.0.0.1:8096/
</VirtualHost>

# Just if is not another app who listening to port 8096
<VirtualHost *:8096>
        ServerName sub2.example.com

        ServerAdmin webmaster@example.com
        DocumentRoot /var/www/my_website

        ErrorLog ${APACHE_LOG_DIR}/my_website_error.log
        CustomLog ${APACHE_LOG_DIR}/my_website_access.log combined

</VirtualHost>

启用虚拟主机:

a2ensite sub2_example_com.conf

重新加载 Apache:

service apache2 reload

在 sub2.example.com 中打开您的网络浏览器,apache 将所有请求重定向到端口 8096

文档阿帕奇: https://httpd.apache.org/docs/current/mod/mod_proxy.html

【讨论】:

    猜你喜欢
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 2012-04-29
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    相关资源
    最近更新 更多