How to serve static files (images, etc.) for the PSGI / Plack web application (in Perl)?

How to serve static files (images, javascript, style sheets) for a PSGI / Plack based web application?

The answer will probably depend on which web server is being used, whether it be CGI, FastCGI, mod_psgi or pure-Perl like Starman. I heard that using Plack :: Middleware :: Static or Plack :: App :: File (along with Plack :: App :: URLMap) should only be used for development ...

+3
source share
1 answer

As for real-time deployment, a very simple (and quick) setup is if you allow the web server with static content and let the Plack application work with dynamic content. This usually requires at least 2 proxies in your web server configuration. Proxy A for your static files (provided that they are all in one place) and proxy B to the port on which your Plack application is deployed.

For example, part of the nginx configuration might look like this. Suppose that the Plack application runs locally on port 5001 and your static files are available under the URL http://mydomainname.com/static

server {
    listen 80;
    server_name mydomainname.com;

    location / {
        proxy_pass http://localhost:5001/;
        proxy_redirect off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Port $server_port;
        proxy_set_header   X-Forwarded-Host $host;
    }

    location /static {                                                                                                                                             
        root /path/to/static/files;                                                                                                                         
    }

}
+6
source

All Articles