如何将一个端口的请求转发/重定向到另一个端口

时间:2014-01-29 09:02:56

标签: apache port portforwarding

是否可能将一个端口的http请求转发或重定向到另一个端口。像这样的请求

http://localhost:8080

转发到另一个端口说8181.并阻止默认端口的所有请求说80.我在运行apache的linux机器上。

3 个答案:

答案 0 :(得分:0)

阅读并关注mod_rewrite文档。

答案 1 :(得分:0)

嘿嘿用户,              您可以使用NameVirtualHost指令从apache配置它,以及mod_proxy模块提供的其他ProxyPass和ProxyPassReverse指令。这是一个基本配置。

    NameVirtualHost *:80
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /var/www/mydomain
ProxyPass / http://localhost:81/
ProxyPassReverse / http://localhost:81/
</VirtualHost>

<VirtualHost *:80>
ServerName www.mydomain2.com
DocumentRoot /var/www/mydomain2
</VirtualHost>

答案 2 :(得分:0)

我不知道为什么它没有重定向到端口8080。

您能发现错误吗?

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyRequests Off

    ServerName ofornecedor.com.br
    ServerAlias http://ofornecedor.com.br

    ProxyPass /admin/event ws://localhost:8080/admin/event
    ProxyPassReverse /admin/event ws://localhost:8080/admin/event

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>


apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Mon 2018-07-30 11:46:14 UTC; 8s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 14742 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 11742 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 14811 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
    Tasks: 55
   Memory: 6.5M
      CPU: 61ms
   CGroup: /system.slice/apache2.service
           ├─14828 /usr/sbin/apache2 -k start
           ├─14831 /usr/sbin/apache2 -k start
           └─14832 /usr/sbin/apache2 -k start

Jul 30 11:46:13 ip-172-31-13-126 systemd[1]: Starting LSB: Apache2 web server...
Jul 30 11:46:13 ip-172-31-13-126 apache2[14811]:  * Starting Apache httpd web server apache2
Jul 30 11:46:13 ip-172-31-13-126 apache2[14811]: [Mon Jul 30 11:46:13.480124 2018] [so:warn] [pid 14827:tid 139956103014272] AH01574: module proxy_module is already loaded, skipping
Jul 30 11:46:13 ip-172-31-13-126 apache2[14811]: [Mon Jul 30 11:46:13.480178 2018] [so:warn] [pid 14827:tid 139956103014272] AH01574: module proxy_http_module is already loaded, skipping
Jul 30 11:46:14 ip-172-31-13-126 apache2[14811]:  *
Jul 30 11:46:14 ip-172-31-13-126 systemd[1]: Started LSB: Apache2 web server.