20190225/5c735e1275537.png

The best life is use of willing attitude, a happy-go-lucky life.

— Mr.Wang

头像

配置Apache反向代理到后端其它软件(ngrok、ASP.NET等)

发布时间:2019-02-25 11:16:34

发布作者:admin

5299

同一个服务器需要部署多个软件,但是80端口只能给一个,这时候我们需要使用反向代理。Nginx的反向代理相对简单,Apache也仅需简单配置即可。

这里特别介绍RewriteRule配置中的[P]标记,这是2.4版的新特性,所以在网络上很多的老旧资料中是找不着的。官方Wiki介绍(英文):http://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_p

以本服务器为例,下面是ngrok的配置文件:

<VirtualHost *:80>

ServerName ngrok.mrpzx.com

ServerAlias *.ngrok.mrpzx.com

RewriteEngine On

RewriteRule ^/(.*) http://%{HTTP_HOST}:8000/$1 [P]

<Proxy *>

Order deny,allow

Allow from all

</Proxy>

ProxyPass / http://localhost:8000/

ProxyPassReverse / http://localhost:8000/

</VirtualHost>

对于ASP.NET WEB API程序,我需要将/跳转到index.html但保持网址不变,配置如下:

<VirtualHost *:80>

ServerName numgame.skitisu.com

RewriteEngine On

# 判断语句,如果请求的参数为/

RewriteCond %{REQUEST_URI} =/

# 那么反代到后端软件的/index.html

RewriteRule / http://localhost:5000/index.html [P]

# 否则正常传递请求参数反代

RewriteRule ^/(.*) http://localhost:5000/$1 [P]

<Proxy *>

Order deny,allow

Allow from all

</Proxy>

ProxyPass / http://localhost:5000/

ProxyPassReverse / http://localhost:5000/

</VirtualHost>


相关文章:
  1. apache和nodejs共用80端口
  2. Mac下Sublime Text Vim模式 方向键无法长按
  3. MacOS 查看端口占用情况
  4. Linux下编译安装MariaDB