Can't start nginx - no errors anywhere - nginx

I am unable to start nginx using the service nginx {signal}.
root# service nginx status
* /usr/sbin/nginx is not running
root# service nginx start
root# service nginx status
* /usr/sbin/nginx is not running
root# ls -al /run/*.pid
-rw-r--r-- 1 root root 5 Jul 23 17:32 /run/acpid.pid
root# /etc/init.d/nginx restart
* Restarting nginx nginx [fail]
root# ls -al /run/*.pid
-rw-r--r-- 1 root root 5 Jul 23 17:32 /run/acpid.pid
-rw-r--r-- 1 root root 0 Jul 25 17:06 /run/nginx.pid
root# service nginx status
* /usr/sbin/nginx is not running
Inside /var/log/nginx/error.log there is only one entry:
2014/07/25 16:59:52 [notice] 17085#0: signal process started
However, neither top, nginx, or netstat show nginx is actually running.
Since I built from source, where might nginx be dying? Where are the log files? /var/log/syslog doesn't seem to have anything about this. I'm not sure where to go from here.

I'm can't add comment :(
file size /run/nginx.pid = 0, nginx can't write pid to file.
start script can't find pid master process
I suspect you need to diff:
pidfile in /etc/init.d/nginx and pid in nginx.conf

Related

Flask + Gunicorn + Nginx: Group www-data not installed

I am new to web services especially when it comes to deployment options.
I made a Flask application webserver, and now I would like to deploy it on production mode. I went for Gunicorn + Nginx options and followed this tutorial on Medium.
I installed nginx with:
~ >>> sudo pacman -S nginx
~ >>> sudo systemctl start nginx
~ >>> sudo systemctl enable nginx
Everything worked well, but when I created my systemd service webserver.service, the Group=www-data made the service exited, with status=216/GROUP.
Here is the webserver.service file:
[Unit]
Description=Gunicorn instance to serve the test server webserver
After=network.target
[Service]
User=user
Group=www-data
WorkingDirectory=/home/user/webserver/
Environment="PATH=/home/user/webserver/.env/bin"
ExecStart=/home/user/webserver/.env/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app
[Install]
WantedBy=multi-user.target
Here is the full log:
~ >>> sudo systemctl start webserver
~ >>> sudo systemctl enable webserver
~ >>> sudo systemctl status webserver
● webserver.service - Gunicorn instance to serve the test server webserver
Loaded: loaded (/etc/systemd/system/webserver.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2020-07-05 14:50:02 CEST; 20min ago
Main PID: 5464 (code=exited, status=216/GROUP)
juil. 05 14:50:02 user systemd[1]: Started Gunicorn instance to serve the test server webserver.
juil. 05 14:50:02 user systemd[5464]: webserver.service: Failed to determine group credentials: No such process
juil. 05 14:50:02 user systemd[5464]: webserver.service: Failed at step GROUP spawning /home/user/webserver/.env/bin/gunicorn: No such process
juil. 05 14:50:02 user systemd[1]: webserver.service: Main process exited, code=exited, status=216/GROUP
juil. 05 14:50:02 user systemd[1]: webserver.service: Failed with result 'exit-code'.
In fact, when I list all the groups, the www-data required by Nginx is missing:
~ >>> groups
sys network power docker lp wheel user
So obviously the above code won't work with www-data group.
What I tried
1. A different group
I tried to change the group option to Group=root, and it worked. I then finished the tutorial without any errors.
I thought it fixed my issue, but I couldn't access my server on my browser at http://www.my_domain_webserver.com, so I guess the www-data is mandatory to work with Nginx and GUnicorn.
My nginx location block:
server {
listen 80;
server_name my_domain_webserver.com www.my_domain_webserver.com;
location / {
include proxy_params;
proxy_pass http://unix:/home/user/webserver/app.sock;
}
}
2. Reloading Daemon
I also tried to re-execute daemon with systemctl daemon-reexec, but it didn't solved my issue.
My project tree is:
webserver
├── app.py
├── app.sock
└── wsgi.py
Why is the group www-data missing ?
Do I need to add special nginx.conf files ? I didn't modify any of them.
Thanks for your help !
You could try to add the folder to the "www-data" group:
sudo chown www-data /home/user/webserver
That helped for me...

Is there a way to resolve an issue with nginx status Active: inactive (dead) problem in CENTOS

This is what it brings when you check nginx status
[root#ttproxyapp conf.d]# service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
sudo systemctl stop apache2
sudo systemctl start nginx
should work since looks like the port is in use (with apache probably)
It realy looks like your NGINX ins't running. nginx -s reload is just working if there is a running instance and therfore a PID-file.
Please check the result of the following command.
[root#localhost conf.d]# sudo ps -elf | grep nginx
Should be something like
1 S root 88262 1 0 80 0 - 13143 sigsus 23:47 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
5 S nginx 88263 88262 0 80 0 - 13257 ep_pol 23:47 ? 00:00:00 nginx: worker process
0 R root 88265 69227 0 80 0 - 28178 - 23:47 pts/1 00:00:00 grep --color=auto nginx
You need at least! the master process and the worker process! If there is no process start your instance by typing
sudo /bin/systemctl start nginx.service OR sudo service nginx start
Check your processlist after running the command.
After you have started the NGINX service there should be PID-file located at
/var/run/nginx.pid and sudo systemctl status nginx.service should printout something like
[root#localhost conf.d]# systemctl status nginx.service
● nginx.service - NGINX Plus - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2020-03-14 23:47:13 EDT; 5min ago
Docs: https://www.nginx.com/resources/
Process: 88232 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 88260 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Process: 88251 ExecStartPre=/usr/libexec/nginx-plus/check-subscription (code=exited, status=0/SUCCESS)
Main PID: 88262 (nginx)
Tasks: 2
Memory: 1.7M
CGroup: /system.slice/nginx.service
├─88262 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─88263 nginx: worker process
Mar 14 23:47:13 localhost.localdomain systemd[1]: Starting NGINX Plus - high performance web server...
Mar 14 23:47:13 localhost.localdomain systemd[1]: Can't open PID file /var/run/nginx.pid (yet?) after start: No such file or directory
Mar 14 23:47:13 localhost.localdomain systemd[1]: Started NGINX Plus - high performance web server.
I am running NGINX Plus but it doesn't matter in this case.
there is maybe an apache server running. you must stop that apache server order run the Nginx server.
sudo systemctl stop apache2
sudo systemctl start nginx

Certbot renew: nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)

Certbot and nginx versions:
certbot installed using certbot.eff.org install guide.
Certbot version: 0.22.2
Nginx version: 1.10.3
Getting ssl certificates works fine:
certbot --nginx
But, in renewal of cerbot certificated
certbot renew --dry-run
nginx fails to start causing:
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
I have tried changing post-hook and pre-hook in /etc/letsencrypt/renewal/*com.conf/
commenting installer=nginx
changing authenticator to nginx and standalone
Adding post and pre hooks in /etc/letsencrypt/renewal-hooks/pre/ and /etc/lestencrypt/renewal-hooks/post/ to stop and start nginx service.
Seems nginx is not starting properly or isn't stop properly.
after renewal completes nginx fails with (code=exited, status=1/FAILURE)
Nginx error log show:
Error while certbot renew:
Try to execute:
sudo service nginx restart
Then test your nginx configuration file(s) (until you see "nginx: configuration file /etc/nginx/nginx.conf test is successful")
sudo nginx -s reload -t
Pay attention on paths to certificates, and other stuff
and then reload configuration without -t option:
sudo nginx -s reload
It's not recommended to modify configuration files in /etc/letsencrypt/ but creating (if it doesn't exist) and modifying cli.ini file here is working for me. You can specify post-hook in this file once and it will work for all your certificates, see my current file:
# /etc/letsencrypt/cli.ini
max-log-backups = 0
authenticator = webroot
webroot-path = /var/www/html
post-hook = service nginx reload
text = True
I hope this will help future readers. Solution source is here (however the article is in Russian)
I had the same issue on Ubuntu 16.04
I've just removed post and pre hooks in /etc/letsencrypt/renewal/*.conf and changed authenticator to nginx - I had in two entries standalone.
And it is working now fine.
Edit:
Recommended way to update renewal config is to reissue new certificate using:
certbot -i nginx -d example.com -d www.example.com certonly
You can run this command line before run reload nginx.
sudo nginx -c /etc/nginx/nginx.conf
or
sudo nginx -c /usr/local/etc/nginx/nginx.conf
then you can start nginx nomaly
sudo nginx -s reload
Good luck.
I had the same error...
When I installed certbot, I followed the instructions and put in a cronjob (5 3 15 * *):
certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start"
this morning nginx was dead, and the log showed
open() "/run/nginx.pid" failed (2: No such file or directory)
I did not connect the two, but do I understand that certbot triggers the nginx failure?
ps -ef | grep nginx, find all nginx process
sudo kill -9 xxx xxx xxx or sudo pkill nginx
sudo systemctl restart nginx
sudo nginx -t
I had this problem and followed a similar tack to those outlined here.
I had had certbot install a certificate, but it was in certonly --nginx mode, I supplied my own nginx serverblocks. certbot worked, but an nginx failure cast doubt on the accuracy of my provisioning.
This certbot call "restarts" nginx with a modified server block configuration, so it can answer the HTTP-01 challenges. I know this because when it fails, it will log, "nginx restart failed:" just before the bind() failures I'm about to show. My nginx server was down when provisioning succeeded.
I couldn't get systemctl or service to start it and systemd status nginx would only ever show "failed".
Whilst I could get nginx up, and serving, with nginx -s reload I wanted systemd to manage it for me.
No amount of systemctl {start|restart|stop|quit} nginx, would work. The status remained as failed and would show errors with bind():
Oct 07 10:04:13 HostXYZ systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 07 10:04:13 HostXYZ nginx[17096]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Oct 07 10:04:13 HostXYZ nginx[17096]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
Oct 07 10:04:13 HostXYZ nginx[17096]: nginx: [emerg] bind() to [::]:443 failed (98: Unknown error)
Oct 07 10:04:13 HostXYZ nginx[17096]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Unknown error)
That would repeat in journalctl output, 4 or 5 times.
I checked the process and saw:
:~$ ps aux | grep nginx
root 12960 0.0 0.6 77216 9816 ? Ss Oct06 0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
www-data 16944 0.0 0.5 77360 8604 ? S 08:43 0:00 nginx: worker process
That process, which appeared to be occupying the ports needed by my systemd service. My systemd service doesn't use that -c /etc/nginx/nginx.conf. It uses:
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
nginx -s stop, and quit would not rid me of the rogue process. Instead they both gave the error the OP had:
:~$ sudo nginx -s stop
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
Both my systemd service unit and /etc/nginx/nginx.conf gave /run/nginx.pid as the PIDFile/pid. For some reason, /etc/nginx/nginx.conf wasn't creating it.
What I needed to do:
sudo killall nginx
sudo systemctl start nginx
That knocked out the other nginx service (I think it came from nginx -s reload but I couldn't shut it down by the corollary command) Which looked like this:
:~$ sudo killall nginx
:~$ ps aux | grep nginx
john 17140 0.0 0.1 4008 2004 pts/0 S+ 10:10 0:00 grep --color=auto nginx
:~$ sudo systemctl start nginx
:~$ sudo systemctl status nginx
● 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 Fri 2022-10-07 10:10:25 UTC; 1s ago
...
:~$ ps aux | grep nginx
root 11481 0.0 0.1 76484 2588 ? Ss 10:10 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 11482 0.0 0.2 76876 4284 ? S 10:10 0:00 nginx: worker process
:~$ cat /run/nginx.pid
11481

Nginx: [emerg] socket() failed (24: Too many open files)

I could see lot more thread created for this issue. Tried all the solutions mentioned on those threads. But None of the options worked for me. So I'm creating this new thread.
OS : CentOS 7.2.1511
Nginx : 1.10.0
Error message:
Nov 2 23:21:36 localhost nginx: Starting nginx: nginx: [emerg] socket() x.x.x.x:80 failed (24: Too many open files)
Nov 2 23:21:36 localhost nginx: [FAILED]
Nov 2 23:21:36 localhost systemd: nginx.service: control process exited, code=exited status=1
Nov 2 23:21:36 localhost systemd: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
Nov 2 23:21:36 localhost systemd: Unit nginx.service entered failed state.
Nov 2 23:21:36 localhost systemd: nginx.service failed.
Ulimit Value:
[root#serv1 nginx]# ulimit -n
16000
[root#serv1 nginx]#
Sysctl.conf:
fs.file-max = 752415
nginx.conf:
worker_rlimit_nofile 30000;
nginx user Ulimit:
[nginx#serv1 ~]$ ulimit -Sn
16000
[nginx#serv1 ~]$ ulimit -Hn
16000
[nginx#serv1 ~]$
Nginx PID max Open files limit:
Max open files 1024 4096 files
Not sure, why the open files limit is not reflected to nginx process. when I checked the pid limit value from proc directory. It shows default value as mentioned above. Values should be 16000 for both soft & hard limits.
Also, I checked the openfiles limit on the server for nginx process. it does not go above 1042.
openfiles :
[root#serv1 ~]# ps -ef | grep nginx
root 4285 1 0 23:12 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/conf/nginx/nginx.conf
nginx 4286 4285 0 23:12 ? 00:00:00 nginx: worker process
root 4308 4290 0 23:12 pts/1 00:00:00 grep --color=auto nginx
[root#serv1 ~]# lsof -p 4285 | wc -l
1042
[root#serv1 ~]#
Someone please help me to fix this problem. Thanks.
Found the problem. its due to nginx.service file was not created as nginx is compiled manually. Once created nginx.service file and added limitonfile value in the file, fixed my problem.
Hope, this may help to people who had hit with this problem.

nginx error log in custom location result in Permission denied (when starting up) on CentOS 7 in Amazon EC2 instance

I am using an AWS EC2 (c3.xlarge) instance with CentOS 7.x and these are my mount points:
[centos#ip-10-0-4-119 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 1.5G 6.6G 18% /
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.5G 0 3.5G 0% /dev/shm
tmpfs 3.5G 17M 3.5G 1% /run
tmpfs 3.5G 0 3.5G 0% /sys/fs/cgroup
/dev/xvdb 40G 49M 38G 1% /mnt
tmpfs 707M 0 707M 0% /run/user/1000
The root partition / is 8gb (for the OS) and I have a 40gb drive mounted on /mnt for the website files. This is a standard setup.
I logged in as root (using sudo su -) and changed the ownership of /mnt to centos:centos (default account you login into).
in this dir, made another directory to store all the error logs here: /mnt/errors (dir perm is 755).
Nginx was installed the nginx.conf has the following lines:
user centos;
worker_processes 4;
error_log /mnt/errors/nginx-errors.log crit;
pid /var/run/nginx.pid;
When I start the nginx server with this command: systemctl start nginx.service I get the following errors:
[centos#ip-10-0-4-119 ~]$ sudo systemctl status nginx
â— nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2016-11-11 02:20:14 UTC; 7min ago
Docs: http://nginx.org/en/docs/
Process: 10394 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
Nov 11 02:20:14 ip-10-0-4-119.localdomain systemd[1]: Starting nginx - high performance web server...
Nov 11 02:20:14 ip-10-0-4-119.localdomain nginx[10394]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Nov 11 02:20:14 ip-10-0-4-119.localdomain nginx[10394]: nginx: [emerg] open() "/mnt/errors/nginx-errors.log" failed (13: Permission denied)
Nov 11 02:20:14 ip-10-0-4-119.localdomain nginx[10394]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 11 02:20:14 ip-10-0-4-119.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 11 02:20:14 ip-10-0-4-119.localdomain systemd[1]: Failed to start nginx - high performance web server.
Nov 11 02:20:14 ip-10-0-4-119.localdomain systemd[1]: Unit nginx.service entered failed state.
Nov 11 02:20:14 ip-10-0-4-119.localdomain systemd[1]: nginx.service failed.
Why am I not able to use a custom location to store the nginx errors?
make sure that the directory where logs will go is readable, writable and executable by the nginx user since that'll be the owner of the nginx worker processes. here's what my nginx log directory looks like:
[root#ip-10-0-1-1 opt]# ls -ld /var/log/nginx/
drwx------ 2 nginx nginx 4096 Nov 11 03:27 /var/log/nginx/
if that doesn't make sense, you can do this:
chmod -R 755 /mnt/errors
chown -R nginx:nginx /mnt/errors
HTH

Resources