2016-12-02 105 views
1

我有一個域名.. sub.example.com,您可以通過端口達到80重定向Apache的子域:80〜8096

每次用戶搜索該域名,我想要得到的redirect to port 8096 ,但用戶不應該意識到這一點。如何配置vHost

+0

的可能的複製[如何轉發子域名到同一個IP地址上的新端口?](http://stackoverflow.com/questions/12715195/how-to-forward-a-subdomain-to-a-new-port-on-the-same-ip -地址) –

回答

0

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

對我來說更好的是代理,因爲客戶端沒有在他的網頁瀏覽器

例爲代理服務器配置查看端口8096:

Firts確保阿帕奇偵聽端口8096:

netstat -laputen|grep 8096 

如果您沒有回覆,請檢查/etc/apache2/ports.conf中的監聽端口:

聽8096

重新啓動Apache和複檢收聽netstat的

service apache2 restart 
netstat -laputen|grep 8096 

如果不是在Apache誰偵聽的端口8096,你只需要創建虛擬主機爲偵聽端口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 [email protected] 
     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 

刷新阿帕奇:

service apache2 reload 

打開在sub2.example.com,Apache的Web瀏覽器重定向端口都要求8096

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