Apache:从文件系统中提供一些URL,其他所有URL都来自Rails应用程序

时间:2009-11-27 11:18:10

标签: apache

我想在Apache Web服务器上托管两个不同的服务,可以通过同一个域访问:一些特殊的URL应该进入文件系统,所有其他的应该由Rails应用程序处理。

示例:

http://mydomain.com/foo/123.txt
=> should deliver /var/www/special/foo/123.txt

http://mydomain.com/users
=> should go to Rails/Passenger

以下是我对Rails应用程序的虚拟主机设置:

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias *.mydomain.com

    DocumentRoot /var/www/mydomain/current/public

    <Directory /var/www/mydomain/current/public>
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
        ExpiresActive on
        ExpiresDefault "access plus 1 year"
        FileETag MTime Size
    </Directory>

    RewriteEngine On

    # Check for maintenance file and redirect all requests
    ErrorDocument 503 /system/maintenance.html
    RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$    -    [redirect=503,last]

    # Rewrite index to check for static
    RewriteRule ^/$ /index.html [QSA]

    # Rewrite to check for Rails cached page
    RewriteRule ^([^.]+)$ $1.html [QSA]

    # Deflate
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/xml application/xhtml+xml text/javascript application/x-javascript

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    ErrorLog /var/log/apache2/mydomain.com-error_log
    CustomLog /var/log/apache2/mydomain.com-access_log combined
</VirtualHost>

在中间某处应该添加RewriteCond / RewiteRule,因此访问http://mydomain.com/foo/123.txt不会转到Rails应用程序,而是转到文件系统。

为此,我需要帮助。如果有人可以给我一个提示,那就太好了。

1 个答案:

答案 0 :(得分:0)

自己找到解决方案:

RewriteCond %{REQUEST_URI} ^/foo/.*$
RewriteRule ^.*$ /var/www/special/foo%{REQUEST_URI}