在 Apache 中设置反向代理的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/719783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:27:52  来源:igfitidea点击:

Issues Setting up a reverse proxy in Apache

apachemod-proxy

提问by Pete

My roommate and I each have a separate webserver we are trying to set up. We are trying to use mod_proxy so that his server will forward requests to my machine (we have two seperate machines behind one router) based on the server name. I've given the basics of what we have in our apache config currently but we are getting a 403 Forbidden error when trying to access the second domain (the first, www domain, works fine).

我和我的室友每个人都有一个我们正在尝试设置的单独的网络服务器。我们正在尝试使用 mod_proxy 以便他的服务器将根据服务器名称将请求转发到我的机器(我们在一个路由器后面有两台不同的机器)。我已经给出了我们当前 apache 配置中的基础知识,但是在尝试访问第二个域(第一个 www 域,工作正常)时,我们收到了 403 Forbidden 错误。

NameVirtualHost *:80

<VirtualHost *:80>
 DocumentRoot /var/www
 ServerName www.<domain1>.com
</VirtualHost>

<VirtualHost *:80>
 ProxyPreserveHost On
 ProxyPass / http://<IP addr of other box>:80
 ProxyPassReverse / http://<IP addr of other box>:80
 ServerName <dummydomain>.gotdns.com
</VirtualHost>

回答by Jeremy Stanley

Your mods-enabled/proxy.conf might be blocking any proxy requests (it's deny all by default). It should include the following instead:

您的 mods-enabled/proxy.conf 可能会阻止任何代理请求(默认情况下全部拒绝)。它应该包括以下内容:

ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

EDIT: Also make sure that the mod_proxy submodules are sym linked into mods-enabled (in this case, the http sub module which is mods-available/proxy_http.load)

编辑:还要确保 mod_proxy 子模块被 sym 链接到 mods-enabled(在这种情况下,http 子模块是 mods-available/proxy_http.load)

回答by permarco

Just put both routes:

只需放两条路线:

<VirtualHost *:80>
    DocumentRoot "/app/"
    ProxyPreserveHost On
    ProxyRequests Off
    ServerName app.yourdomain.com

    ProxyPass /app http://yourIP:yourPort/app/
    ProxyPassReverse /app http://yourIP:yourPort/app/

    ProxyPass / http://yourIP:yourPort/app/
    ProxyPassReverse / http://yourIP:yourPort/app/
</VirtualHost>

<Location "/app/" >
    ProxyPass "http://yourIP:yourPort/app/"
    ProxyPassReverse  "http://yourIP:yourPort/app/"
    ProxyPassReverseCookiePath  "/app/"  "/app/"
    ProxyHTMLEnable Off
    ProxyHTMLExtended On
    ProxyHTMLURLMap "/app/" "/app/"
    Order allow,deny
    Allow from all
</Location>

This worked form me

这对我有用