【问题标题】:Apache Reverse Proxy not rewriting URLs the way I expectApache 反向代理没有按照我期望的方式重写 URL
【发布时间】:2012-10-05 00:55:53
【问题描述】:

我对 Apache 很陌生,希望设置一个反向代理以便能够访问我从一个站点获得的一些 IP 摄像机的 Web 界面。我使用的基本布局如下:

                             / Cam 1 - 192.168.1.10  
Reverse Proxy - 192.168.1.6 -
                             \ Cam 2 - 192.168.1.11

当我点击无法正确解析的链接时,URL 应该是 http://192.168.1.6/cam1/settings.htm,但它会解析为 http://192.168.1.6/setting.htm

Not Found
The requested URL /setting.htm was not found on this server.
Apache/2.2.22 (Debian) Server at 192.168.1.6 Port 80

我的配置在这里,我使用标准的 httpd.conf 并启用了代理和重写模块:

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

<VirtualHost *>
        Servername webserver
        RewriteEngine on

        RewriteRule ^/cam1/(.*)$ http://192.168.1.10$1 [P]
        RewriteRule ^/cam2/(.*)$ http://192.168.1.11$1 [P]

        ProxyPass /cam1 http://192.168.1.10
        ProxyPassReverse /cam1 http://192.168.1.10
        ProxyPass /cam2 http://192.168.1.11
        ProxyPassReverse /cam2 http://192.168.1.11

</VirtualHost>

任何帮助将不胜感激。

干杯, 亚当

【问题讨论】:

  • 您是否遇到任何错误或者您可以在此处打印日志?
  • 这是日志中出现的内容...很多次 [Mon Oct 15 10:14:32 2012] [error] [client 192.168.1.112] 文件不存在:/var/www /lang,referer:192.168.1.6/controlmenu.htm [Mon Oct 15 10:14:32 2012] [error] [client 192.168.1.112] 文件不存在:/var/www/jpg,referer:192.168.1.6/main.htm [Mon Oct 15 10 :14:32 2012] [错误] [客户端 192.168.1.112] 文件不存在:/var/www/style,引用者:192.168.1.6/controlmenu.htm

标签: apache apache2 debian reverse-proxy mod-proxy


【解决方案1】:

在日志中您可以清楚地看到缺少一些文件,例如 File does not exist: /var/www/jpg/var/www/lang 所以可能这就是你的存储问题的原因。我敢打赌你错过了一些配置,而服务器或你的服务器由于一些其他文件而在运行时损坏了这些文件。我建议你重新下载然后重新安装。

【讨论】:

  • 如果我输入完整路径 http//192.168.1.6/cam1/.../page.htm 它会解析,但如果我转到 192.168.1.6/cam1 并单击刚刚引用为页面的链接.htm 然后我得到错误。反向代理是否应该处理“非完整路径”链接并将其重定向到正确的路径。
【解决方案2】:

对于未来的用户:

cat /etc/apache2/sites-available/default

<VirtualHost *:80>
    ServerAdmin user@work.com.br

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from 192.168.5.25
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ProxyPass               /cameras/               http://192.168.5.6/
    ProxyPassReverse        /cameras/               http://192.168.5.6/

【讨论】:

    猜你喜欢
    • 2022-12-13
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 2014-03-24
    • 2021-10-21
    • 2019-08-27
    • 1970-01-01
    • 2014-02-01
    相关资源
    最近更新 更多