nginx installed with https://nginx.org/en/linux_packages.html in Ubuntu 18.04
sudo apt -y install curl gnupg2 ca-certificates lsb-release ;
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list ;
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add - ;
sudo apt update ;
sudo apt install nginx ;
nginx up and running
$ ps -aux | grep nginx
root 5602 0.0 0.0 33348 880 ? Ss 17:03 0:00 nginx: master process nginx
nginx 5603 0.0 0.0 33744 2748 ? S 17:03 0:00 nginx: worker process
with /etc/nginx/nginx.conf
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
allow publish 127.0.0.1;
deny publish all;
}
}
}
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -f flv rtmp://localhost/live/test yields
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, lavfi, from 'testsrc':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[tcp # 0x5611668b8c00] Connection to tcp://localhost:1935 failed: Connection refused
[rtmp # 0x5611668b8520] Cannot open connection tcp://localhost:1935
rtmp://localhost/live: Connection refused
Clue:
Nothing seems to be listening on port 1935. netstat -tap | grep 1935 yields nothing
Clue2:
Albeit ps shows app as running, systemctl status nginx.service shows app status down
● nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2020-12-03 19:37:17 CET; 7min ago
Docs: http://nginx.org/en/docs/
Process: 5709 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
Things checked given other stackoverflow questions:
trying to connect to rtmp://localhost/live/test and in nginx.conf the application is correctly named live
nginx.conf correctly placed at /etc/nginx/, no other nginx.conf files exist, and nginx -s reload called to make sure it is loaded
no localhost instances in the conf file, all renamed to 127.0.0.1
Install nginx that supports rtmp sudo apt install nginx-core nginx-common libnginx-mod-rtmp
and not sudo apt install nginx
and then run nginx with
sudo systemctl restart nginx
Related
I'm new to using Nginx as a reverse proxy, and here is my /etc/nginx/conf.d/default.conf:
server {
listen 80;
location /myip/ {
proxy_pass http://checkip.dyndns.com/;
proxy_set_header Host http://checkip.dyndns.com/;
}
}
and this line in /etc/nginx/nginx.conf is active:
include /etc/nginx/conf.d/*.conf;
I was expecting to see a page about my IP address when I visited http://localhost/myip/, but I got 404 instead. Any ideas why so? Meanwhile http://localhost is correctly showing nginx's welcoming page.
More details about my env:
Clean debian VM in GCP
Nginx installed via sudo apt install nginx
server status (sudo systemctl status nginx) is looking good:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-03-08 01:27:50 UTC; 6min ago
Docs: man:nginx(8)
Process: 4237 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exite
d, status=0/SUCCESS)
Process: 3342 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCES
S)
Process: 4242 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 4239 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 4244 (nginx)
Tasks: 3 (limit: 4915)
CGroup: /system.slice/nginx.service
├─4244 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─4245 nginx: worker process
└─4246 nginx: worker process
Mar 08 01:27:50 marqeta-proxy-test systemd[1]: Stopped A high performance web server and a reverse proxy server.
Mar 08 01:27:50 marqeta-proxy-test systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 08 01:27:50 marqeta-proxy-test systemd[1]: Started A high performance web server and a reverse proxy server.
I want to deploy an flask app and followed a tutorial to get this done using nginx.
As the tutorial states I do as follows:
sudo nano /etc/nginx/sites-available/app
this file contains:
server {
listen 80;
server_name server_domain_or_IP;
location / {
include proxy_params;
proxy_pass http://unix:/home/pi/Desktop/python_scripts/internetdisplay/app.sock;
}
}
A systemd Unit service was created and is succesfully running. This created the app.sock file in the 'internetdisplay' directory. Systemctl status app.service results:
● app.service - Gunicorn instance to serve myproject
Loaded: loaded (/etc/systemd/system/app.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-11-10 21:16:49 CET; 16h ago
Main PID: 438 (gunicorn)
Tasks: 4 (limit: 2200)
Memory: 46.4M
CGroup: /system.slice/app.service
├─438 /usr/bin/python2 /usr/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app
├─679 /usr/bin/python2 /usr/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app
├─681 /usr/bin/python2 /usr/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app
└─682 /usr/bin/python2 /usr/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app
Nov 10 21:16:49 raspberrypi systemd[1]: Started Gunicorn instance to serve myproject.
Nov 10 21:16:57 raspberrypi gunicorn[438]: [2019-11-10 21:16:57 +0000] [438] [INFO] Starting gunicorn 19.9.0
Nov 10 21:16:57 raspberrypi gunicorn[438]: [2019-11-10 21:16:57 +0000] [438] [INFO] Listening at: unix:app.sock (438)
Nov 10 21:16:57 raspberrypi gunicorn[438]: [2019-11-10 21:16:57 +0000] [438] [INFO] Using worker: sync
Nov 10 21:16:57 raspberrypi gunicorn[438]: [2019-11-10 21:16:57 +0000] [679] [INFO] Booting worker with pid: 679
Nov 10 21:16:57 raspberrypi gunicorn[438]: [2019-11-10 21:16:57 +0000] [681] [INFO] Booting worker with pid: 681
Nov 10 21:16:57 raspberrypi gunicorn[438]: [2019-11-10 21:16:57 +0000] [682] [INFO] Booting worker with pid: 682
Then I link to sites-enabled and restart nginx:
sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled
sudo systemctl restart nginx
But surfing to http://localhost leads to an "this site can't be reached" error
It sounds like your location block is not set up correctly to find your resourses.
I assume that this is not the location of your unix socket:
/home/tasnuva/work/deployment/src/app.sock
Check the following:
systemd unit file is creating a socket in the expected location
the daemon is indeed running and the socket file exists
your nginx config is pointing to the correct socket file.
If none of this tells you anything, please update your question with appropriate error log entries.
I'm having trouble getting gunicorn and Nginx to work together and allow me to offer a simple API via flask:
Locally, running gunicorn and getting responses from the server works fine:
gunicorn wsgi:app (start server)
[2019-06-11 23:12:48 +0000] [14615] [INFO] Starting gunicorn 19.9.0
[2019-06-11 23:12:48 +0000] [14615] [INFO] Listening at: http://127.0.0.1:8000 (14615)
[2019-06-11 23:12:48 +0000] [14615] [INFO] Using worker: sync
[2019-06-11 23:12:48 +0000] [14619] [INFO] Booting worker with pid: 14619
curl http://127.0.0.1:8000/predict (client call server for prediction)
output: "SERVER WORKS"
The problem arises when I try to use Nginx as well.
/etc/systemd/system/app.service
[Unit]
Description=Gunicorn instance to serve app
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/server
ExecStart=/usr/local/bin/gunicorn --bind unix:app.sock -m 007 wsgi:app
[Install]
WantedBy=multi-user.target
/etc/nginx/sites-available/app
server {
listen 80;
server_name [SERVER_IP_ADDRESS];
location / {
include proxy_params;
proxy_pass http://unix:/root/server/app.sock;
}
}
The status of my systemd looks fine:
systemctl status app
● app.service - Gunicorn instance to serve app
Loaded: loaded (/etc/systemd/system/app.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-06-11 23:24:07 UTC; 1s ago
Main PID: 14664 (gunicorn)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/app.service
├─14664 /usr/bin/python /usr/local/bin/gunicorn --bind unix:app.sock -m 007 wsgi:app
└─14681 /usr/bin/python /usr/local/bin/gunicorn --bind unix:app.sock -m 007 wsgi:app
systemd[1]: Started Gunicorn instance to serve app.
gunicorn[14664]: [2019-06-11 23:24:07 +0000] [14664] [INFO] Starting gunicorn 19.9.0
gunicorn[14664]: [2019-06-11 23:24:07 +0000] [14664] [INFO] Listening at: unix:app.sock (14664)
gunicorn[14664]: [2019-06-11 23:24:07 +0000] [14664] [INFO] Using worker: sync
gunicorn[14664]: [2019-06-11 23:24:07 +0000] [14681] [INFO] Booting worker with pid: 14681
When I make a request to the server, I have trouble connecting:
curl http://[SERVER_IP_ADDRESS]:80/predict
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.14.0 (Ubuntu)</center>
</body>
</html>
EDIT:
I tried removing server_name [SERVER_IP_ADDRESS]; from /etc/nginx/sites-available/app. I now receive 'Welcome to nginx!' at http://SERVER_IP_ADDRESS, and '404 Not Found' at http://SERVER_IP_ADDRESS/predict
FYI, my flask app only has one route, which is '/predict'
It looks like you don't have Port 80 open, so here's a quick iptables command to do so:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
I am having trouble with my nginx server not wanting to start. could someone with the appropriate knowledge try to diagnose my error code and give me some kind of guidance as to how I can fix my issue? This is my first time posting so if you need anymore information please let me know. Thanks (:
michael#productionserver1:~$ sudo systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
michael#productionserver1:~$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2016-07-14 05:50:29 EDT; 16s ago
Process: 3754 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/
Process: 2269 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=ex
Process: 3598 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, statu
Process: 5641 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exit
Main PID: 3600 (code=exited, status=0/SUCCESS)
lines 1-8/8 (END)
I got this when running " nginx -t " nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed: (13 Permission denied) 2016/07/14 07:32:23 [warn] 6060#6060: the "user" directive makes sense only if the master process runs with super-suer privileges, ignored in /etc/nginx/nginx.conf:1 2016/07/14 07:32:23 [emerg] 6060#6060: a duplicate default server for 0.0.0.0:44 3 in /etc/nginx/sites-enabled/example.com:34 nginx: configuration file /etc/nginx/nginx.conf text failed
my knowledge of networks are very poor!!, am a newbie!! ;-)
I have a small server streaming ffmpeg installed on nginx with 2 network interfaces
p2p1 is used for WAN which provides http/ssh....
p4p1 is used to receive multicast data from intranet.
192.168.0.1 is public network gateway.
192.168.1.1 is private network gateway (commented for not have internet exit this network)
239.0.0.*/24 is multicast address.
Linux distribution
3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Distributor ID : Ubuntu
Description: Ubuntu 14.04.2 LTS
Release : 14.04
Codename : trusty
My network interfaces config
auto lo
iface lo inet loopback
# NET1
auto p2p1
iface p2p1 inet static
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
# NET2
auto p4p1
iface p4p1 inet static
address 192.168.1.100
netmask 255.255.255.0
### gateway 192.168.1.1
Now my route table
root#srv:# route
Tabla de rutas IP del núcleo
Destino Pasarela Genmask Indic Métric Ref Uso Interfaz
default 192.168.0.1 0.0.0.0 UG 0 0 0 p2p1
192.168.0.0 * 255.255.255.0 U 0 0 0 p2p1
192.168.1.0 * 255.255.255.0 U 0 0 0 p4p1
I'm using udpxy on port 4022 for converting IPTV multicast to unicast HTTP
udpxy -p 4022
I execute this
/usr/bin/ffmpeg -i "http://127.0.0.1:4022/rtp/239.0.0.76:8208" -map 0:0 -map 0:1 -c:v libx264 -vf scale=-1:720 -r 25 -profile:v high -level:v 4.0 -crf 18 -preset veryfast -maxrate 2000k -bufsize 2200k -c:a aac -ab 128k -strict -2 -ac 2 -f flv rtmp://127.0.0.1:11111/rtmp/channel1;
ffmpeg version 2.7 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
http://127.0.0.1:4022/rtp/239.0.0.76:8208: Invalid data found when processing input
as I can solve this problem??
Thanks in advance
210.0.0.0/24 are not multicast addresses.
The IPv4 multicast range is 224.0.0.0/4. See https://en.wikipedia.org/?title=Multicast_address
It's quite possible that's the reason you're having issues.
Edit:
Also note the error message:
http://127.0.0.1:4022/rtp/239.0.0.76:8208: Invalid data found when processing input
I suppose that means there's a problem getting data from udpxy, so try running that verbose (udpxy -v -p 4022) and see what it says.