重定向Apache子域:80至8096



我有一个域。 sub.example.com,您可以通过端口80到达。

用户每次搜索该域,我都想获得redirect to port 8096,但是用户不应该意识到。

有人对此有建议如何配置vHost

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

对我来说越好的是代理人,因为客户在他的网络浏览器中未查看您的端口8096

示例为代理配置:

firts确保apache在端口8096上收听:

netstat -laputen|grep 8096

如果您没有答复,请在/etc/apache2/ports.conf中检查端口:

听8096

重新启动Apache,然后在Netstat中收听

service apache2 restart
netstat -laputen|grep 8096

如果不是听端口8096的Apache,您只需要创建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

中的所有请求

doc apache:https://httpd.apache.org/docs/current/mod/mod/mod_proxy.html

最新更新