A route to serve static assets (like .jpgs, etc?)

前端 未结 5 1266
后悔当初
后悔当初 2021-02-02 16:19

I\'ve worked my way through a number of interesting routing problems - turning a request URL into a hash, etc., but just out of curiosity, is there a way to tell the routing sys

5条回答
  •  死守一世寂寞
    2021-02-02 16:50

    I typically use nginx as a frontend and Apache/Passenger as a backend. Ngingx proxies all Rails requests to Apache but handles all static content itself. Check out the examples on the English nginx wiki. Here is a small excerpt for nginx config:

    server {
        listen 80;
        server_name www.domain.com;
        location ~* \.(jpg|jpeg|gif|png|ico|css|bmp|js)$ {
            root   /path/to/static/assets/dir;
        }
        location / {
            proxy_pass http://127.0.0.1:81;
        }
    }
    

    So have apache listen on port 81 to handle Rails requests proxied by nginx and let nginx deliver static content. Not only is nginx supposedly faster than Apache at delivering static content, but this also offloads your Rails application for every image, stylesheet, javascript or whatever other static content.

提交回复
热议问题