Dash streaming on Nginx Plus - nginx

I have hls working on nginx plus, as per this gist: https://gist.github.com/45sound/0ed2d8f971314facf72c
I assumed I could add a new location like this:
location /dash{
dash;
root /var/www
}
but I get nginx: [emerg] unknown directive "dash" in /etc/nginx/conf.d/default.conf:21 when I restart server.
Ideally I want to serve hls and dash content from same server.
Best,
Vinny
FanFootage.com
Edit: http://nginx-rtmp.blogspot.ie/2013/11/mpeg-dash-live-streaming-in-nginx-rtmp.html is the example i followed, and both "dash" and "dash on" gives the same error.

Nginx Plus supports Apple HLS and Adobe HDS for video-on-demand (VOD) only. There is no mention of a DASH module.
You can always DASH yourself the files for VOD (eg: with the GPAC MP4Box) and just serve the segments and manifests from any location block directly without a module.
The Nginx RTMP module offers support for MPEG-DASH live streaming. It also works with the basic version:
rtmp {
server {
[...]
application dash {
live on;
dash on;
dash_path /tmp/dash;
}
}
}
http {
server {
listen 8080;
[...]
location /dash {
root /tmp;
add_header Cache-Control no-cache;
}
}
}

The NGINX RTMP Module (supports DASH) is available with NGINX Plus. It can be found in the NGINX Plus Extras Package.

Related

Download files in remote server using reverse proxy Nginx

I have a server running with Nginx reverse proxy.
We have our application running in another server, which is served using this Nginx proxy. Below is the configuration I have used and its working fine.
location / {
rewrite ^/(.*) /$1 break;
proxy_pass http://10.0.0.121:8000;
}
I would need to download a pdf file in the application machine (10.0.0.121) , which is under /home/ubuntu/app/pdf/data-2021-03-25.pdf.
How could I make the file in application machine downloadable from the proxy server, please help.
Thanks in Advance.
I would simply install another nginx instance on 10.0.0.121 and configure it like this. NON-PROD READY!
server {
listen 8080;
server_name ...;
root /home/ubuntu/app/pdf;
location = /data-2021-03-25.pdf {
try_files $uri $uri/ =404;
}
server {
listen 8090;
location / {
proxy_pass http://localhost:8080;
}
}
}
Not tested but this server will handling the request serving the file. Then you could just use proxy_pass on the other server to proxy the request.
But beside from this option you can use a python, perl, php, java, nodejs, assembly or what ever programming language you want to use to open a http port and serve the file on an incoming request. Its really your choice.
just make sure if you're going for the proxy solution you are sanitizing the requests on your proxy. For example. With a small change in the setup above you could cheat and get any other files from your home/app directory by sending an request like curl -v localhost:8090/pdf/../other/file. So make sure you are using the root(/home/ubuntu/app/pdf/) directive and set a location matching the pdf-file on the proxy-server as well.
That worked in my demo app.

nginx ignores my site configuration

I created site config file in dir /etc/nginx/sites-enabled
server {
listen 80;
server_name domain.com;
gzip_types application/x-javascript text/css;
access_log /var/log/nginx/nodeApp.info9000p.access.log;
location / {
proxy_pass http://127.0.0.1:9000/;
}
location ~ ^/(min/|images/|bootstrap/|ckeditor/|img/|javascripts/|apple-touch-icon-ipad.png|apple-touch-icon-ipad3.png|apple-touch-icon-iphone.png|apple-touch-icon-iphone4.png|generated/|js/|css/|stylesheets/|robots.txt|humans.txt|favicon.ico) {
root /root/Dropbox/nodeApps/nodeApp/9000/appdirectory-build;
access_log off;
expires max;
}
}
and restarted nginx:
sudo /etc/init.d/nginx restart
But nginx ignore my site config file and shows default page, when I request domain.com :
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
Where are your Wordpress-files located?
The default nginx htdocs-root is /usr/share/nginx/html
If you've installed the files at, say, /usr/share/nginx/html/wordpress, then you must change the root-setting in the file /etc/nginx/conf.d/default.conf to that directory, like this
server {
root /usr/share/nginx/html/wordpress;
}
Plese read the https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 article on how to set up nginx to work with the PHP-engine over socket (CentOS) if you have not already done so.
Don't know how, but my configuration started to work well. Maybe because I restarted nginx instead of reload it.

uwsgi and nginx simple setup without virtual env

are there any steps to setup uwsgi with nginx with a simple wsgi python script. Most of the places I see only django and flask and other frameworks are being setup. Also I need steps to serve static files.. are there any .. ?
Obviously there are two steps: uwsgi configuration and nginx configuration.
The simplest uwsgi configuration is as follows (uwsgi accepts many different configuration formats, in this example I use xml):
<uwsgi>
<chdir>/path/to/your/script/</chdir>
<pythonpath>/path/to/your/script/</pythonpath>
<processes>2</processes>
<module>myscript.wsgi:WSGIHandler()</module>
<master/>
<socket>/var/run/uwsgi/my_script.sock</socket>
</uwsgi>
The only tricky option here is module, it should point to your WSGI handler class.
Also, make sure that /var/run/uwsgi/my_script.sock is readable and writeable for both uwsgi and nginx.
The corresponding nginx configuration would look like this:
server {
listen 80;
server_name my.hostname;
location / {
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/my_script.sock;
}
}
If you need to serve static files, the smiplest way would be to add following code to the server clause:
location /static/ {
alias /path/to/static/root/;
gzip on;
gzip_types text/css application/x-javascript application/javascript;
expires +1M;
}
This example already includes gzip compression and support for browser cache.

Reverse proxy for a subdirectory with nginx and Play 2.1 apps

Goal
Setup multiple Play 2.1 applications with nginx using different subdirectory for each application.
App1 running on 127.0.0.1:4000 should be accessible under 127.0.0.1/dev
App2 running on 127.0.0.1:5000 should be accessible under 127.0.0.1/test
Configuration
nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
upstream app1 {
server 127.0.0.1:4000;
}
upstream app2 {
server 127.0.0.1:5000;
}
server {
listen 80;
server_name localhost;
location /dev {
rewrite /(.*) /$1 break;
proxy_pass http://app1;
}
location /test {
rewrite /(.*) /$1 break;
proxy_pass http://app2;
}
}
}
App1 - application.conf
application.context=/dev
App2 - application.conf
application.context=/test
Problem
With this configuration I can access both applications, but only html code is loaded. All static files (css, js, images) aren't loaded.
I think this is caching problem. I've tried with different nginx parameters, without luck. If I request the site for the first time the browser responds (for css and js files, e.g. 127.0.0.1/dev/assets/stylesheets/main.css) with status 200 but without content - Content-Length: 0. For the next time it responds with 304, still without content.
I'm not sure if this is nginx or Play 2.1 configuration problem.
I will appreciate any help.
Use local domains like http://test.loc/ and http://dev.loc instead of relying on subfolders. Although application.context should work I saw many posts complaining that they don't...
What's more using local domains is more similar to the final - production enviroment, so it's just easier to debug some url depended things, like ie. cookies.
Even though this doesn't directly answer your question, I got it to work in HAProxy by passing the X-Script-Name parameter:
frontend public
bind *:80
use_backend playapp if { path_beg /playapp }
backend playapp
acl is-ssl dst_port 443
reqadd X-Script-Name:\ /playapp
reqadd X-Scheme:\ https if is-ssl
option forwardfor
server playapp1 127.0.0.1:9000 check

Struggling with location blocks in nginx config

I got a new slice off slicehost, for the purposes of playing around and learning nginx and more about deployment generally. I installed a ruby app on there (which i'll call app1) which uses passenger. I made it the default app to use for that server with the following server block in my nginx config:
server {
listen 80;
server_name <my server ip>;
root <path to app1 public folder>;
passenger_enabled on;
}
This works fine. However, i want to try a few different apps out on this slice, and so thought i would set it up like so:
http:///app1
http:///app2
etc. I thought i would be able to do that by adding a location block, and moving the app1 specific stuff into it like so:
server {
listen 80;
server_name <my server ip>;
location ^~ /app1 {
root <path to app1 public folder>;
passenger_enabled on;
}
}
However, on doing this (and restarting nginx of course), going to the plain ip address gives the 'welcome to nginx' message (which i'd expect). But, going to /app1 gives an error message:
404 Not Found
The requested URL /app1 was not found on this server.
This is distinct from the error message i get when i go to another path on that ip, eg /foo:
404 Not Found
nginx/0.8.53
So, it's like nginx knows about that location but i've not set it up properly. Can anyone set me straight? Should i set up different server blocks instead of using locations? I'm sure this is simple but can't work it out.
Cheers, max
What you're after is name virtual hosting. The idea is that each domain is hosted on the same IP, and nginx chooses the virtualhost to serve based on the Host: header in the HTTP request, which is sent by the browser.
To use name virtual hosting, use the domain you want to serve instead of your server's IP for the server_name directive.
server {
listen 80;
server_name app1.com;
location / {
root /srv/http/app1/public;
passenger_enabled on;
}
}
Then, to host more apps on the same box, just declare a separate server { } block for each one.
server {
listen 80;
server_name app2.com;
location / {
root /srv/http/app2/public;
passenger_enabled on;
}
}
I'm using unicorn instead of passenger, but the vhost part of the structure is the same for any backend.
The global nginx config (which on its own hosts nothing): https://github.com/benhoskings/babushka-deps/blob/master/nginx/nginx.conf.erb
The template wrapper for each virtualhost: https://github.com/benhoskings/babushka-deps/blob/master/nginx/vhost.conf.erb
The details of the unicorn virtualhost: https://github.com/benhoskings/babushka-deps/blob/master/nginx/unicorn_vhost.common.erb
I fail to see the real problem here tho,
in order for you to figure that out
you need to view the nginx log files on most systems at:
/var/log/nginx/
and open the relevant access file here(might be error.log)
in there you can see what url nginx exactly tried to access and why did it fail.
What I really think is happening, that you got the root path wrong,
maybe it should be alias instead because
if you are proxifying the connection to another app, it might get the
"app1" word in the url instead of a direct one.
so please try:
server {
listen 80;
server_name <my server ip>;
location /app1 {
alias <path to app1 public folder>;
passenger_enabled on;
}
}
and see weather it works and also try to view the logs first to really determine whats the problem.
I think its just a slight syntax problem:
location ~ ^/app1 { ...
should work, or a little more efficient:
location = /app1 { ...
One problem is that your Rails app probably wasn't designed to run from a subdirectory. Passenger has a directive that will fix this:
passenger_base_uri /app1;
However, running Rails apps in subdirectories is somewhat non-standard. If you can, a better option may be to set up subdomains using nginx's virtual hosts.
It seems that you want to host more apps on the same server with base uri. Try this:
root /srv/http/;
passenger_base_uri /app_1;
passenger_base_uri /app_2
Also under /srv/http, create 2 symlinks:
ln -s /srv/http/app_1 /srv/http/app1/public
ln -s /srv/http/app_2 /srv/http/app2/public
The app1 can be accessed under: http://domain.com/app_1.
Here is more for reading: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rack_to_sub_uri

Resources