[英]Apache: Using reverse proxy and run local website
On my linux machine I have apache2 running as a reverse proxy, because I wanted to make another webserver on port 8083 accessible while also making it password protected. 在我的linux机器上,我将apache2作为反向代理运行,因为我想在端口8083上创建另一个Web服务器,同时也使其受密码保护。 For this I added this to my apache2.conf:
为此,我将此添加到我的apache2.conf中:
<VirtualHost *:80>
<Location / >
AuthName "Protected Area"
AuthType Basic
AuthUserFile /home/pi/.htpasswd
Require valid-user
</Location>
ProxyPass / http://localhost:8083/
ProxyPassReverse / http://localhost:8083/
</VirtualHost>
That works like a charm, but now I also want to use apache to serve a site, I would like to do this by making something like /mysite point to /var/www, but I can't really figure out how to do this or if it is even possible. 这就像一个魅力,但现在我也想用apache来服务一个网站,我想通过制作/ mysite指向/ var / www之类的东西来做到这一点,但我无法弄清楚如何做到这一点或者如果可能的话。
Any ideas? 有任何想法吗?
I think you have two options: 我想你有两个选择:
1. Put the proxy in a separate <Location /someurl>
and put the site outside. 1.将代理放在单独的
<Location /someurl>
,并将该站点放在外面。 Requests to http://localhost/someurl/
will be proxied, everything else is the local site: 对
http://localhost/someurl/
请求将被代理,其他所有内容都是本地站点:
<VirtualHost *:80>
<Location /someurl >
# Password protection omitted for brevity
ProxyPass http://localhost:8083/
ProxyPassReverse http://localhost:8083/
</Location>
# Here is the site
DocumentRoot /var/www
# ... etc site config
</VirtualHost>
2. Use two separate VirtualHosts
, one for the proxy and one for the site. 2.使用两个单独的
VirtualHosts
,一个用于代理,一个用于站点。 You will need two separate hostnames pointing to your local ip. 您将需要两个指向本地IP的单独主机名。 For local operations only, use
/etc/hosts
. 仅对于本地操作,请使用
/etc/hosts
。 In this exemple http://a.localhost/
is the proxy, http://b.localhost
is the site: 在这个例子中,
http://a.localhost/
是代理, http://b.localhost
是网站:
/etc/hosts: / etc / hosts中:
127.0.0.1 a.localhost
127.0.0.1 b.localhost
Apache config: Apache配置:
# This is the proxy, http://a.localhost/
<VirtualHost *:80>
ServerName a.localhost
# Do password protection as needed
ProxyPass / http://localhost:8083/
ProxyPassReverse / http://localhost:8083/
</VirtualHost>
# This is the site, http://b.localhost/
<VirtualHost *:80>
ServerName b.localhost
DocumentRoot /var/www
# ... etc site config
</VirtualHost>
I would probably go for two separate VirtualHosts
, keeping stuff nicely separated. 我可能会去两个独立的
VirtualHosts
,保持很好的分离。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.