Apache / Unicorn:如何让 Apache 提供静态文件服务

Apache / Unicorn:如何让 Apache 提供静态文件服务

我正在跟进本教程安装 apache + unicorn,但似乎 apache 不提供任何静态文件。这是我提出的配置(请Redirect all non-static requests to unicorn特别查看):

<VirtualHost *:80>
  ServerName www.unstilted.com:80
  ServerAlias *.unstilted.com
  DocumentRoot /var/www/unstilted/current/public

  ErrorDocument 503 /system/maintenance.html

  RewriteEngine On

  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{REQUEST_FILENAME} !/system/maintenance.html
  RewriteRule ^.*$    /system/maintenance.html [L]

  # Rewrite to check for Rails non-html cached pages (i.e. xml, json, atom, etc)
  RewriteCond  %{THE_REQUEST} ^(GET|HEAD)
  RewriteCond  %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_URI} -f
  RewriteRule  ^(.*)$ /cache/%{HTTP_HOST}$1 [QSA,L]

  # Rewrite to check for Rails cached html page
  RewriteCond  %{THE_REQUEST} ^(GET|HEAD)
  RewriteCond  %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}%{REQUEST_URI}.html -f
  RewriteRule  ^(.*)$ /cache/%{HTTP_HOST}$1.html [QSA,L]

  # no www
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ http://%1$1 [R=301,L]

  <Proxy balancer://unicornservers>
    BalancerMember http://127.0.0.1:5000
  </Proxy>

  # Redirect all non-static requests to unicorn
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]

  ProxyPass / balancer://unicornservers/
  ProxyPassReverse / balancer://unicornservers/
  ProxyPreserveHost on

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

在我的/var/www/unstilted/current/public目录中我有 robots.txt,但是当我转到 时mydomain.com/robots.txt,请求会转到 unicorn,而 apache 不会处理它。

我的配置有什么问题?如何让 Apache 提供静态文件?

谢谢!

答案1

%{DOCUMENT_ROOT}在这种情况下 丢失。%{REQUEST_FILENAME}是文件的完整文件系统(不是 URL)路径,因此应该像这样匹配:

RewriteCond %{REQUEST_FILENAME} !-f

相关内容