我想使用 Nodejs/Apache 代理传递来提供我的 API,但是在添加下面的 apache(httpd)配置后,似乎配置不起作用。
操作系统:
CentOS 6
/etc/httpd/conf/httpd.conf:
...
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/MyUser/public_html
<Directory />
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /api>
ProxyPass http://MyVpsIp:1337
ProxyPassReverse http://MyVpsIp:1337
</Location>
</VirtualHost>
...
后:
sudo service httpd restart
在浏览器中打开 example.com/api:
Not Found
The requested URL /api was not found on this server.
编辑:当我example.com:1337/api
在浏览器中打开时,一切都正常!但我想要example.com/api
答案1
代理目标需要以斜线结尾。试试这个:
ProxyPass /api/ http://132.159.25.21:8080/
ProxyPassReverse /api/ http://132.159.25.21:8080/