1.Apache
1.启用proxy模块
Windows:修改httpd.conf配置文件,去掉以下两行前面 # 号,从而启用Apache proxy module。
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Ubuntu:
sudo apt-get install libapache2-mod-proxy-html sudo apt-get install libxml2-dev sudo a2enmod proxy proxy_http
2.配置virtualHost
<VirtualHost *:80> ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /apis http://ip_address/apis ProxyPassReverse /apis http://ip_address/apis </VirtualHost>
1.ProxyRequests Off 指令是指采用反向(reverse)代理
2.ProxyPass 指令允许将一个远端服务器映射到本地服务器的URL空间中
3.ProxyPassReverse 它一般和ProxyPass指令配合使用,此指令使Apache调整HTTP重定向应答中Location, Content-Location, URI头里的URL,这样可以避免在Apache作为反向代理使用时,后端服务器的HTTP重定向造成的绕过反向代理的问题
4.配置完成之后,访问 http://localhost/apis 实际就是访问 http://ip_address/apis上的资源
2.Nginx
配置server
server { listen 80; server_name localhost; charset utf8; access_log /var/log/nginx_api/access.log; error_log /var/log/nginx_api/error.log; location / { root html; index index.html index.htm; } location /apis { rewrite ^.+apis/?(.*)$ /$1 break; include uwsgi_params; proxy_pass http://ip_address/apis; } }