【问题标题】:Nginx reverse proxy (static files rewrite in apache)Nginx 反向代理(在 apache 中重写静态文件)
【发布时间】:2012-11-16 04:08:17
【问题描述】:

我在 Apache 前使用 Nginx(设置为反向代理)有一些问题。我正在使用 Apache 来提供 PHP 文件并应用 .htaccess 规则。

Nginx 有效,但 .htaccess 中的某些重写无效。

我使用 timthumb.php 来管理媒体,例如:

/cache/150/100/file.jpg > /media/thumb.php?src=images/file.jpg&w=150&h=100

重写规则仅适用于 PHP 应用程序,但不适用于上述静态文件。 当我尝试执行自己的静态规则时,Nginx 返回 404。

RewriteEngine On

RewriteRule ^cache/([0-9]+)/([0-9]+)/([a-z0-9_\-\.\/]+)$ /media/thumb.php?src=images/$3&w=$1&h=$2 [L]
RewriteRule ^upload/([0-9]+)/([0-9]+)/([a-z0-9_\-\.\/]+)$ /media/thumb.php?src=upload/$3&w=$1&h=$2 [L]

<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT]

【问题讨论】:

    标签: apache mod-rewrite nginx hosting reverse-proxy


    【解决方案1】:

    我猜你是通过 nginx 直接为你的“/upload”和“/cache”目录提供服务 - 没有将它传递给 apache。

    尝试以下规则:

     location ^~ /upload {
            .......
     }
    
     location ^~ /cache {
            .......
     }
    

    在您在 nginx 配置中提供静态文件的位置之前。让我知道它是否有效 - 如果没有 - 也粘贴 nginx 配置的一部分。

    更多阅读:http://wiki.nginx.org/HttpCoreModule#location

    取决于您在代理期间如何配置位置 - 它们具有不同的优先级。

    【讨论】:

      猜你喜欢
      • 2017-09-09
      • 2012-03-26
      • 2016-08-19
      • 2019-04-17
      • 2023-04-09
      • 2012-09-08
      • 2014-03-17
      • 2014-02-01
      • 2020-12-18
      相关资源
      最近更新 更多