Apache转发请求到另一服务器端口

By admin, 11 十月, 2019

一般服务器中以及成绩云服务器的移动版都是用8002端口和8443端口来响应请求。但是也有特殊的情况无法使用指定的端口,此时可以使用代理技术实现[[BR]]
'''1.加载apache模块,使用a2enmod命令加载模块'''[[BR]]
{{{
 a2enmod proxy proxy_balancer proxy_http 
}}}
一般都是默认就开启的,开启后会有提示需要重启apache服务,
{{{
sudo apache2ctl -k restart
}}}
'''2.配置反向代理,进入/etc/apache2/sites-available,编辑000-default.conf文件配置相关代理'''[[BR]]
{{{
#off表示开启反向代理,on表示开启正向代理
ProxyRequests Off
ProxyMaxForwards 100
ProxyPreserveHost On

#这里表示要将请求转发到8002端口
ProxyPass /goapi/ http://127.0.0.1:8002/
ProxyPassReverse /goapi/ http://127.0.0.1:8002/
       
<Proxy /goapi>
       Order Deny,Allow
       Allow from all
</Proxy>
}}}
那么一条如下的URI请求: http://113.12.185.74:85/goapi/user/get-login-notice/gxnnbzgz 会被转发到 http://127.0.0.1:8002/user/get-login-notice/gxnnbzgz 来响应,而前端是不知道这个变化的。[[BR]]
相应地,我们的JS代码中,需要把​http://113.12.185.74:85/goapi/ 作为Goapi服务器前缀。

评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal10"