I have the following nginx configuration that I believe -- or at least hope -- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX? server { listen 80; server_name mydomain.com; rewrite ^/(.*) https://mydomain.com/$1 permanent; } server { listen 443 ssl; server_name mydomain.com; ssl_certificate /home/starman/mydomain.com.chained.crt; ssl_certificate_key /home/starman/mydomain.com.key; client_max_body_size 20M; location / { # Serve static files directly: if (-f $request_filename) { expires 30d; break; } proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:5000; } }
On Tue, Mar 8, 2016 at 3:45 PM, Richard Reina <gatorreina@gmail.com> wrote:
I have the following nginx configuration that I believe -- or at least hope -- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Stop the Dancer application and try to load the static files directly. Gabor
You can set the access_log directive in 'location' context. Il giorno mar 8 mar 2016 alle ore 15:29 Gabor Szabo <gabor@szabgab.com> ha scritto:
On Tue, Mar 8, 2016 at 3:45 PM, Richard Reina <gatorreina@gmail.com> wrote:
I have the following nginx configuration that I believe -- or at least hope -- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Stop the Dancer application and try to load the static files directly.
Gabor
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Gabor, Thanks for the idea. I tried accessing an image from (public) images directory and it came right up with the dancer app running. Then I stoped the dancer app with "service starman stop" (as I used your tutorial http://perlmaven.com/getting-started-with-perl-dancer-on-digital-ocean when for my setup :) ) and when I refreshed the page with my dancer app stoped I got: 502 Bad Gateway ------------------------------ nginx/1.6.2 Any idea how I can fix my nginx configuration to truly serve static files directly (without dancer)? 2016-03-08 8:28 GMT-06:00 Gabor Szabo <gabor@szabgab.com>:
On Tue, Mar 8, 2016 at 3:45 PM, Richard Reina <gatorreina@gmail.com> wrote:
I have the following nginx configuration that I believe -- or at least hope -- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Stop the Dancer application and try to load the static files directly.
Gabor
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Quoting Richard Reina <gatorreina@gmail.com>:
I have the following nginx configuration that I believe -- or at least hope -- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Before you go too far down this route, have you considered using Plack::Middleware::Static instead? https://metacpan.org/pod/Plack::Middleware::Static Dave...
Hi Dave, Thanks for the reply. I think I am already using it via starman. use Daemon::Control; use Cwd qw(abs_path); Daemon::Control->new( { name => "Starman", lsb_start => '$syslog $remote_fs', lsb_stop => '$syslog', lsb_sdesc => 'Starman Short', lsb_desc => 'Starman controls the web sites.', path => abs_path($0), program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/mydomain/bin/app.psgi' ], user => 'starman', group => 'starman', pid_file => '/tmp/starman.pid', stderr_file => '/tmp/starman.err', stdout_file => '/tmp/starman.out', fork => 2, } )->run; 2016-03-08 8:41 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I have the following nginx configuration that I believe -- or at least hope
-- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Before you go too far down this route, have you considered using Plack::Middleware::Static instead?
https://metacpan.org/pod/Plack::Middleware::Static
Dave...
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
[ re-ordered to preserve readability ] Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 8:41 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I have the following nginx configuration that I believe -- or at least hope
-- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Before you go too far down this route, have you considered using Plack::Middleware::Static instead?
Hi Dave,
Thanks for the reply. I think I am already using it via starman.
use Daemon::Control;
use Cwd qw(abs_path);
Daemon::Control->new( { name => "Starman", lsb_start => '$syslog $remote_fs', lsb_stop => '$syslog', lsb_sdesc => 'Starman Short', lsb_desc => 'Starman controls the web sites.', path => abs_path($0),
program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/mydomain/bin/app.psgi' ],
user => 'starman', group => 'starman',
pid_file => '/tmp/starman.pid', stderr_file => '/tmp/starman.err', stdout_file => '/tmp/starman.out',
fork => 2,
} )->run;
I can't see an evidence of you using Plack::Middleware::Static (or, indeed, any Plack middleware). It would't be added to your Starman runner, it would be in your app.psgi (as described in the Pod that I linked to). Dave...
Hi Dave, You are correct. I am obioulsy mistaken. In my development (non production) app which I run on a local machine (not digital ocean) I use plack via plackup -p 5000 bin/app.psgi. However, going through my old notes I now rememeber that I was not able to incorporate plack with my starman configuration above. I tried and for reasons that I cannot remember was unsuccessful and opted for: program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/Almslete/bin/app.psgi' ], Specifically, I believe that I originally tried something like: program => 'plackup -E deployment -s Starman', plackup -E deployment -s Starman --workers=10 -p 5001 -a bin/app.psgi Any advice on how I can move forward on incorporating plack so that I can then incorporate Plack::Middleware::Static would of course be greatly appreciated. Thanks 2016-03-08 9:02 GMT-06:00 Dave Cross <dave@dave.org.uk>:
[ re-ordered to preserve readability ]
Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 8:41 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I have the following nginx configuration that I believe -- or at least hope
-- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Before you go too far down this route, have you considered using Plack::Middleware::Static instead?
Hi Dave,
Thanks for the reply. I think I am already using it via starman.
use Daemon::Control;
use Cwd qw(abs_path);
Daemon::Control->new( { name => "Starman", lsb_start => '$syslog $remote_fs', lsb_stop => '$syslog', lsb_sdesc => 'Starman Short', lsb_desc => 'Starman controls the web sites.', path => abs_path($0),
program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/mydomain/bin/app.psgi' ],
user => 'starman', group => 'starman',
pid_file => '/tmp/starman.pid', stderr_file => '/tmp/starman.err', stdout_file => '/tmp/starman.out',
fork => 2,
} )->run;
I can't see an evidence of you using Plack::Middleware::Static (or, indeed, any Plack middleware).
It would't be added to your Starman runner, it would be in your app.psgi (as described in the Pod that I linked to).
Dave...
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
[ re-ordered (again) in a vain attempt to preserve readability ] Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 9:02 GMT-06:00 Dave Cross <dave@dave.org.uk>:
[ re-ordered to preserve readability ]
Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 8:41 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I have the following nginx configuration that I believe -- or at least hope
-- serves up my static files, like images ad videos, directly without invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Before you go too far down this route, have you considered using Plack::Middleware::Static instead?
Hi Dave,
Thanks for the reply. I think I am already using it via starman.
use Daemon::Control;
use Cwd qw(abs_path);
Daemon::Control->new( { name => "Starman", lsb_start => '$syslog $remote_fs', lsb_stop => '$syslog', lsb_sdesc => 'Starman Short', lsb_desc => 'Starman controls the web sites.', path => abs_path($0),
program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/mydomain/bin/app.psgi' ],
user => 'starman', group => 'starman',
pid_file => '/tmp/starman.pid', stderr_file => '/tmp/starman.err', stdout_file => '/tmp/starman.out',
fork => 2,
} )->run;
I can't see an evidence of you using Plack::Middleware::Static (or, indeed, any Plack middleware).
It would't be added to your Starman runner, it would be in your app.psgi (as described in the Pod that I linked to).
Hi Dave,
You are correct. I am obioulsy mistaken. In my development (non production) app which I run on a local machine (not digital ocean) I use plack via plackup -p 5000 bin/app.psgi. However, going through my old notes I now rememeber that I was not able to incorporate plack with my starman configuration above. I tried and for reasons that I cannot remember was unsuccessful and opted for:
program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/Almslete/bin/app.psgi' ],
Specifically, I believe that I originally tried something like:
program => 'plackup -E deployment -s Starman', plackup -E deployment -s Starman --workers=10 -p 5001 -a bin/app.psgi
Any advice on how I can move forward on incorporating plack so that I can then incorporate Plack::Middleware::Static would of course be greatly appreciated.
I think we're talking at cross-purposes here. You don't need to be running plackup in order to use Plack middleware. You just need to be running a PSGI app - which you are, it's in your app.psgi. Assuming that you're using the app,psgi that dancer2 originally generated for you, then it will look something like this: #!/usr/bin/env perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use MyWebApp; MyWebApp->to_app; (Obviously substituting the name of your app for "MyWebApp".) To add Plack::Middleware::Static, you would change it to look something like this: #!/usr/bin/env perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use Plack::Builder; use MyWebApp; builder { enable 'Plack::Middleware::Static', path => qr{^/(javascripts|css)/} , root => './public/'; MyWebApp->to_app; }; To (attempt to) be completely clear - you can use Plack middleware with any PSGI app. You don't need to be running it under plackup. Running it under Starman (or any other PSGI server) will work just as well. Hope that's clearer. Dave...
I think we're talking at cross-purposes here.
You don't need to be running plackup in order to use Plack middleware. You just need to be running a PSGI app - which you are, it's in your app.psgi.
Assuming that you're using the app,psgi that dancer2 originally generated for you, then it will look something like this:
#!/usr/bin/env perl
use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib";
use MyWebApp; MyWebApp->to_app;
(Obviously substituting the name of your app for "MyWebApp".)
To add Plack::Middleware::Static, you would change it to look something like this:
#!/usr/bin/env perl
use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib";
use Plack::Builder;
use MyWebApp;
builder { enable 'Plack::Middleware::Static', path => qr{^/(javascripts|css)/} , root => './public/'; MyWebApp->to_app; };
To (attempt to) be completely clear - you can use Plack middleware with any PSGI app. You don't need to be running it under plackup. Running it under Starman (or any other PSGI server) will work just as well.
Hope that's clearer.
Dave...
Dave,
Thank you for the very clear and isntructive reply. Sorry about the top-post earlier. I wil try your recipe. I take it that I should inlcude the name of any directories such as 'images' (along with javascript & css ) in ./public that I want plack to serve directly correct? Again, thank you very much for your help. Richard
Quoting Richard Reina <gatorreina@gmail.com>:
I take it that I should inlcude the name of any directories such as 'images' (along with javascript & css ) in ./public that I want plack to serve directly correct?
Yes, that's right. Sorry, I'd removed 'images' from my example, because my app didn't use them. Dave...
2016-03-08 10:22 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I take it that I should inlcude the name of any directories such as
'images' (along with javascript & css ) in ./public that I want plack to serve directly correct?
Yes, that's right. Sorry, I'd removed 'images' from my example, because my app didn't use them.
Dave...
Hi Dave, I tried it and the app works fine. Thanks. However, is there a way to test that is actually verify the files are bing served directly? It's not that I doubt it, just want to make sure as I will be serving some rather large files.
Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 10:22 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I take it that I should inlcude the name of any directories such as
'images' (along with javascript & css ) in ./public that I want plack to serve directly correct?
Yes, that's right. Sorry, I'd removed 'images' from my example, because my app didn't use them.
Hi Dave,
I tried it and the app works fine. Thanks. However, is there a way to test that is actually verify the files are bing served directly? It's not that I doubt it, just want to make sure as I will be serving some rather large files.
Simple approach - change the "root" directory in the plugin set-up to one that doesn't exist. Reload and see that your images disappear. Dave...
2016-03-08 10:51 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 10:22 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I take it that I should inlcude the name of any directories such as
'images' (along with javascript & css ) in ./public that I want plack to serve directly correct?
Yes, that's right. Sorry, I'd removed 'images' from my example, because my app didn't use them.
Hi Dave,
I tried it and the app works fine. Thanks. However, is there a way to test that is actually verify the files are bing served directly? It's not that I doubt it, just want to make sure as I will be serving some rather large files.
Simple approach - change the "root" directory in the plugin set-up to one that doesn't exist. Reload and see that your images disappear.
Dave...
Changed to: path => qr{^/(javascripts|css|images|profile_pics|user_vids)/} , root => './fontsXX/'; and refresshed a sort of makeshift dashboard page and all the non-text content dissapeared accept the embeded videos on that page which are in public/user_vids/ and are displayed with the following markup. <% IF Vids.size %> <div class="vcenter"> <div class="row"> <div class="col-md-offset-1 col-md-10"> <div class="wraptocenter"> <h5><b>My Videos:</b></h5> <% FOREACH v IN Vids %> <!--<p>Video: <% v %></p> <p><% v.substr(8, 1) %></p> --> <% IF v.substr(8, 1) == 'L' %> <video controls preload="auto" width="568" height="320"> <% ELSE %> <video controls preload="auto" width="320" height="568"> <% END %> <!-- <video controls="true" preload="auto"> --> <source src='user_vids/<% v %>.mp4' type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> <source src='user_vids/<% v %>.ogv' type='video/ogg; codecs="theora, vorbis"' /> <!-- <source src='user_vids/<% v %>.webm' type='video/webm;codecs="vp8, vorbis"' /> --> </video> <% END %> </div> </div> </div> </div> <% END %> Any idea why they persist?
2016-03-08 11:14 GMT-06:00 Richard Reina <gatorreina@gmail.com>:
2016-03-08 10:51 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 10:22 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I take it that I should inlcude the name of any directories such as
'images' (along with javascript & css ) in ./public that I want plack to serve directly correct?
Yes, that's right. Sorry, I'd removed 'images' from my example, because my app didn't use them.
Hi Dave,
I tried it and the app works fine. Thanks. However, is there a way to test that is actually verify the files are bing served directly? It's not that I doubt it, just want to make sure as I will be serving some rather large files.
Simple approach - change the "root" directory in the plugin set-up to one that doesn't exist. Reload and see that your images disappear.
Dave...
Changed to: path => qr{^/(javascripts|css|images|profile_pics|user_vids)/} , root => './fontsXX/';
and refresshed a sort of makeshift dashboard page and all the non-text content dissapeared accept the embeded videos on that page which are in public/user_vids/ and are displayed with the following markup.
<% IF Vids.size %> <div class="vcenter"> <div class="row"> <div class="col-md-offset-1 col-md-10"> <div class="wraptocenter"> <h5><b>My Videos:</b></h5> <% FOREACH v IN Vids %> <!--<p>Video: <% v %></p> <p><% v.substr(8, 1) %></p> --> <% IF v.substr(8, 1) == 'L' %> <video controls preload="auto" width="568" height="320"> <% ELSE %> <video controls preload="auto" width="320" height="568"> <% END %> <!-- <video controls="true" preload="auto"> --> <source src='user_vids/<% v %>.mp4' type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> <source src='user_vids/<% v %>.ogv' type='video/ogg; codecs="theora, vorbis"' /> <!-- <source src='user_vids/<% v %>.webm' type='video/webm;codecs="vp8, vorbis"' /> --> </video> <% END %> </div> </div> </div> </div> <% END %>
Any idea why they persist?
After playing around with this I have come ot believe that the videos must
have been cached. Further testing shows just he video outline and controls.
On Tue, Mar 8, 2016 at 3:45 PM, Dave Cross <dave@dave.org.uk> wrote:
[ re-ordered (again) in a vain attempt to preserve readability ]
Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 9:02 GMT-06:00 Dave Cross <dave@dave.org.uk>:
[ re-ordered to preserve readability ]
Quoting Richard Reina <gatorreina@gmail.com>:
2016-03-08 8:41 GMT-06:00 Dave Cross <dave@dave.org.uk>:
Quoting Richard Reina <gatorreina@gmail.com>:
I have the following nginx configuration that I believe -- or at least hope
-- serves up my static files, like images ad videos, directly without
invoking my dancer app. Can anyone tells me if this is the case or not, or how I can test to see if they are indeed being served directly by NGINX?
Before you go too far down this route, have you considered using Plack::Middleware::Static instead?
Hi Dave,
Thanks for the reply. I think I am already using it via starman.
use Daemon::Control;
use Cwd qw(abs_path);
Daemon::Control->new( { name => "Starman", lsb_start => '$syslog $remote_fs', lsb_stop => '$syslog', lsb_sdesc => 'Starman Short', lsb_desc => 'Starman controls the web sites.', path => abs_path($0),
program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/mydomain/bin/app.psgi' ],
user => 'starman', group => 'starman',
pid_file => '/tmp/starman.pid', stderr_file => '/tmp/starman.err', stdout_file => '/tmp/starman.out',
fork => 2,
} )->run;
I can't see an evidence of you using Plack::Middleware::Static (or, indeed, any Plack middleware).
It would't be added to your Starman runner, it would be in your app.psgi (as described in the Pod that I linked to).
Hi Dave,
You are correct. I am obioulsy mistaken. In my development (non production) app which I run on a local machine (not digital ocean) I use plack via plackup -p 5000 bin/app.psgi. However, going through my old notes I now rememeber that I was not able to incorporate plack with my starman configuration above. I tried and for reasons that I cannot remember was unsuccessful and opted for:
program => '/usr/local/bin/starman', program_args => [ '--workers', '3', '/home/starman/Almslete/bin/app.psgi' ],
Specifically, I believe that I originally tried something like:
program => 'plackup -E deployment -s Starman', plackup -E deployment -s Starman --workers=10 -p 5001 -a bin/app.psgi
Any advice on how I can move forward on incorporating plack so that I can then incorporate Plack::Middleware::Static would of course be greatly appreciated.
I think we're talking at cross-purposes here.
You don't need to be running plackup in order to use Plack middleware. You just need to be running a PSGI app - which you are, it's in your app.psgi.
Assuming that you're using the app,psgi that dancer2 originally generated for you, then it will look something like this:
#!/usr/bin/env perl
use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib";
use MyWebApp; MyWebApp->to_app;
(Obviously substituting the name of your app for "MyWebApp".)
To add Plack::Middleware::Static, you would change it to look something like this:
#!/usr/bin/env perl
use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib";
use Plack::Builder;
use MyWebApp;
builder { enable 'Plack::Middleware::Static', path => qr{^/(javascripts|css)/} , root => './public/'; MyWebApp->to_app; };
To (attempt to) be completely clear - you can use Plack middleware with any PSGI app. You don't need to be running it under plackup. Running it under Starman (or any other PSGI server) will work just as well.
Hope that's clearer.
Dave...
Does anyone know the difference in speed of serving static content through Plack::Middleware::Static vs directly through Nginx? Here's one person's attempt to get closer to Nginx performance (without saying what that is:) https://metacpan.org/pod/Plack::Middleware::Static::OpenFileCache Andrew
participants (5)
-
Andrew Solomon -
Dave Cross -
Gabor Szabo -
Mariano Spadaccini -
Richard Reina