Enabling Video Streaming with NGINX - nginx

I have just enabled nginx for Live Video Streaming. I followed the article (https://www.nginx.com/blog/video-streaming-for-remote-learning-with-nginx/). When I run
sudo nginx I am getting the warnings below
nginx: [warn] duplicate extension "ts", content type: "video/mp2t", previous content type: "video/mp2t" in /etc/nginx/nginx.conf:39
nginx: [warn] duplicate extension "html", content type: "text/html", previous content type: "text/html" in /etc/nginx/nginx.conf:40
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] still could not bind() ```
Can someone please help me resolve this error. I have also included the config file for nginx. The article does not really give clear instructions for not so linux tech savvy people, it's missing some steps and doesn't really indicate where to put what.

Related

nginx - Failed to restart process

I've got no errors in my config, as tested with nginx -t
root#proxy1:/var/www# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
However when I try running systemctl restart nginx, I get the following error.
root#proxy1:/var/www# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
Running systemctl status nginx.service returns
● 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 Sun 2022-10-09 19:43:09 CEST; 48s ago
Docs: man:nginx(8)
Process: 1439643 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1439658 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Oct 09 19:43:08 SERVERHOSTNAME.net nginx[1439658]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Oct 09 19:43:09 SERVERHOSTNAME.net nginx[1439658]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Oct 09 19:43:09 SERVERHOSTNAME.net nginx[1439658]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 09 19:43:09 SERVERHOSTNAME.net nginx[1439658]: nginx: [emerg] bind() to 0.0.0.0:3582 failed (98: Address already in use)
Oct 09 19:43:09 SERVERHOSTNAME.net nginx[1439658]: nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
Oct 09 19:43:09 SERVERHOSTNAME.net nginx[1439658]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Oct 09 19:43:09 SERVERHOSTNAME.net nginx[1439658]: nginx: [emerg] still could not bind()
Oct 09 19:43:09 SERVERHOSTNAME.net systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Oct 09 19:43:09 SERVERHOSTNAME.net systemd[1]: nginx.service: Failed with result 'exit-code'.
Oct 09 19:43:09 SERVERHOSTNAME.net systemd[1]: Failed to start A high performance web server and a reverse proxy server.
However all my sites running on nginx are functional.
I also get problems related to this while running certbot.
root#proxy1:/var/www# certbot
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
...
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for MYDOMAIN.net
nginx: [error] invalid PID number "" in "/run/nginx.pid"
Cleaning up challenges
nginx: [error] invalid PID number "" in "/run/nginx.pid"
nginx restart failed:
b''
b''
I'm not sure if it's a bug of Nginx, but you may try this (worked for me):
pkill -9 nginx
nginx -c /etc/nginx/nginx.conf
nginx -s reload
Source

NGINX Process Stops: bind failed, kill failed, pid disappeared

My NGINX is doing weird things I don't understand:
Every day or even multiple times a day, the process just stops.
This is the error log file:
2022/04/15 09:49:23 [notice] 9327#9327: signal process started
2022/04/15 09:49:23 [alert] 9327#9327: kill(9311, 1) failed (3: No such process)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:8888 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:8888 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:8888 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:8888 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:80 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to [::]:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:443 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: bind() to 0.0.0.0:8888 failed (98: Address already in use)
2022/04/15 09:49:23 [emerg] 9328#9328: still could not bind()
lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
Also, at other point (when working with certbot) I have noticed that the pid file disappeared.
I think, what is happening is, that some service is restarting NGINX and trying to take the ports that are still reserved by the not yet stoped old service, so the new service errors out and then finally the old service stops.
I checked, that no other process is interfering and taking these ports, I also don't have apache2 installed. This lets me to believe what I described above.
I can restart NGINX using systemctl restart nginx or using killall nginx; systemctl start nginx.
Interesting side note: It happens, that systemctl status nginx show the NGINX process as 'failed' but NGINX is still running. I believe this is due to the missing pid file.
If you have any idea, how I can debug this or fix it, I'd be really thankful. This is not a state I can leave my webserver in. I'd be happy to provide any information or log you might need.
I found the solution:
Your problem sounds familiar. One earlier case was this thread. It
is long so I will summarize here.
Do you by chance have perl enabled? If so, try disabling it, restart
nginx and see if that allows the renew.
Why? A conflict with nginx can result using the nginx plug-in as after
it makes the temp changes to your nginx conf it reloads it using
SIGHUP. That's fine but if that fails it will start nginx but not
using systemd. This creates an nginx that cannot be managed by systemd
and the two nginx fight each other for ports leading to the symptom
you saw.
Now, various things can cause the SIGHUP to fail. A common one is not
having nginx running before doing the renew. Of course then the sighup
will fail. You said nginx was running so likely not your cause.
I mention perl only because that explained the SEGV that the nginx
sighup was failing with in the thread I linked to. We would have to
dig through your system logs like we did in this linked thread. But,
it would be a quick test if you had perl just to disable it.
A work-around is to use webroot as that avoids the nginx plug-in
altogether. Webroot uses your running nginx as it is.
Source: Lets Encrypt Forum: https://community.letsencrypt.org/t/auto-renewal-nginx-pid-disappears-nginx-doest-restart/179794
Solution by MikeMcQ

nginx service failed (Result: exit-code) Job for nginx.service failed

I've been trying to apply an SSL to my droplet, but the nginx gives me an error when I try to execute the certbot.
● 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 Fri 2018-10-19 13:50:49 UTC; 39s ago
Docs: man:nginx(8)
Process: 18860 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 18850 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Oct 19 13:50:47 All-line nginx[18860]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 19 13:50:47 All-line nginx[18860]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Oct 19 13:50:48 All-line nginx[18860]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 19 13:50:48 All-line nginx[18860]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Oct 19 13:50:48 All-line nginx[18860]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Oct 19 13:50:48 All-line nginx[18860]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Oct 19 13:50:49 All-line nginx[18860]: nginx: [emerg] still could not bind()
Oct 19 13:50:49 All-line systemd[1]: nginx.service: Control process exited, code=exited status=1
Oct 19 13:50:49 All-line systemd[1]: nginx.service: Failed with result 'exit-code'.
Oct 19 13:50:49 All-line systemd[1]: Failed to start A high performance web server and a reverse proxy server.
If You use certbot, this helped me. Updating certbot and updating of letsencrypt config files.

our nginx server is stopping on its own

We have an express app running on port 3000 using pm2 process manager. We are using nginx to reverse proxy the requests to the node app. But all of sudden nginx stops running on its own. It happened a few days ago, we did a restart and it worked then. But today it failed once again. At that time when we check nginx status it gives this output,
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 Sat 2018-09-22 12:38:52 UTC; 1h 43min ago
Process: 21571 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCES
Process: 21680 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 21676 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 8027 (code=exited, status=0/SUCCESS)
Sep 22 12:38:51 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 22 12:38:51 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] still could not bind()
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: nginx.service: Control process exited, code=exited status=1
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: nginx.service: Unit entered failed state.
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: nginx.service: Failed with result 'exit-code'.
And this is the nginx error.log
2018/09/22 12:38:41 [warn] 21539#21539: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:48 [warn] 21641#21641: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:48 [notice] 21641#21641: signal process started
2018/09/22 12:38:48 [error] 21641#21641: open() "/run/nginx.pid" failed (2: No such file or directory)
2018/09/22 12:38:48 [warn] 21642#21642: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:50 [warn] 21676#21676: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:50 [warn] 21680#21680: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: still could not bind()
2018/09/22 12:38:52 [alert] 21643#21643: unlink() "/run/nginx.pid" failed (2: No such file or directory)
Any idea why it is happening? Is something wrong with our nginx configuration or our node app is somehow causing the trouble?
Per logs it seems something is already using port 80 and 443. It could be anything. Also in some rare cases it could be nginx itself. Then i would reccomend to restart server.
i would start pin pointing what actually uses those port by:
# netstat -tulpn | grep :80
# netstat -tulpn | grep :443
Then would check nginx error logs to find out more
tail -n 500 /var/log/nginx/error.log
then if you find some other app using those ports you could check what those are:
# whatis <appName>
# whereis <appName>
If it is caused by different app then you can either turn it of or rebind it to another port.
Hope it helps :)

Change Nginx port from 80

Im trying to change the port that Nginx uses from port 80 to 5555
I've gone into nano /etc/nginx/sites-enabled/default
and edited:
server {
listen 5555;
}
But when I try to restart I get:
$ service nginx restart
Restarting nginx: nginx.
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
Am I missing something?
Another service is the port.
Use sudo netstat -plnt to see which service is using the port and stop it, or configure it otherwise.
Also check out this and this.

Resources