Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu下Apache反向代理设置 #12

Open
ttop5 opened this issue Oct 30, 2016 · 0 comments
Open

Ubuntu下Apache反向代理设置 #12

ttop5 opened this issue Oct 30, 2016 · 0 comments

Comments

@ttop5
Copy link
Owner

ttop5 commented Oct 30, 2016

反向代理:

客户端能访问外部的web,但是不能访问目标web,目标web所在的网络内一台机器充当目标web的代理,客户端直接访问代理就像访问目标web一样(此代理对客户端透明,即客户端不用做如何设置,并不知道实际访问的只是代理而已,以为就是访问的目标)。

适用情况:

  • idc的某台目标机器只对内开放web,外部的客户端要访问,就让另一台机器做proxy,外部直接访问proxy即相当于访问目标;
  • idc的目标机器的某个特殊的web服务跑在非正常端口如5000,而防火墙上只对外开放了80端口,此时可在80端口上做proxy映射到5000端口,外部访问80端口即相当于5000端口。

具体设置:

第一步,首先是要打开apache的相关功能。

sudo a2enmod rewrite #打开 url 重写
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer

第二步,设置网站的配置文件,在 /etc/apache2/sites-available/ 目录下 新建文件 a.com, 写入如下内容

ServerName a.com 
ProxyPreserveHost On 
ProxyRequests Off 

Order deny,allow 
Allow from all 

ProxyPass / http://192.168.0.10/ 
ProxyPassReverse / http://192.168.0.10/

第三步,在/etc/apache2/sites-enabled/目录下把刚才建的文件做个软链接过来

sudo ln -s ../sites-available/a.com a.cm

第四步,执行、启用这个站点

sudo a2ensite a.com 
sudo service apache2 reload

或者直接重启apache服务

sudo service apache2 restart

这样所有来自 a.com 的请求都会转发到 http://192.168.0.10, 祝你好运!

@ttop5 ttop5 added this to the 旧wp博客迁移 milestone Oct 30, 2016
@ttop5 ttop5 self-assigned this Oct 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant