Install of openresty : nginx.pid not found - nginx

I try to install OpenResty 1.13.6.1 under CentOS 7. When I try to run openresty I get this error:
[root#flo ~]# openresty -s reload
nginx: [error] open() "/usr/local/openresty/nginx/logs/nginx.pid" failed (2: No such file or directory)
When I look at my logs, I only have 2 files:
[root#flo ~]# ll /usr/local/openresty/nginx/logs/
total 8
-rw-r--r--. 1 root root 0 1 mars 12:24 access.log
-rw-r--r--. 1 root root 4875 1 mars 16:03 error.log
I do not see how to find a solution.
///////////////////UPDATE//////////////////
I try to do this to folow the instructions of this page : https://openresty.org/en/getting-started.html
[root#flo ~]# PATH=/usr/local/openresty/nginx/sbin:$PATH
[root#flo ~]# export PATH
[root#flo ~]# nginx -p pwd/ -c conf/nginx.conf
And I have this error :
nginx: [alert] could not open error log file: open() "/root/logs/error.log" failed (2: No such file or directory)
2018/03/02 09:02:55 [emerg] 30824#0: open() "/root/conf/nginx.conf" failed (2: No such file or directory)
/////////////////UPDATE2//////////////:
[root#nexus-chat1 ~]# cd /root/
[root#nexus-chat1 ~]# ll
total 4
-rw-------. 1 root root 1512 1 mars 11:05 anaconda-ks.cfg
drwxr-xr-x. 3 root root 65 1 mars 11:36 openresty_compilation
Where do I need to create these folders ?
mkdir ~/work
cd ~/work
mkdir logs/ conf/
In /usr/local/openresty/ ?

Very likely nginx cannot open a log file because folder doesn't exists or permission issue.
You can see the reason within error.log file

openresty -s reload is used to tell nginx to reload the currently running instance. That's why it's complaining about the missing pid file.
Anyway, that's not the correct way to start openresty. Have a look at https://openresty.org/en/getting-started.html for instructions on how to get started.

Related

No nginx folders after installing on Amazon Linux 2 EC2 instance

I'm trying to install Nginx on an EC2 instance running Amazon Linux 2. After running the commands as listed here on: https://stackoverflow.com/a/61256478/11309912.
Checking the version shows that is installed.
nginx -v
nginx version: nginx/1.22.0
But either under /etc or /local there is no nginx folder being created.
nginx -t does run but fails:
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2022/11/13 13:33:46 [emerg] 16016#16016: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
I tried running sudo yum remove nginx and sudo yum install nginx/sudo amazon-linux-extras install -y nginx1 but both to no avail.
Is there a way to (re)install nginx that places these folders and configs?

How to recreate nginix.pid when I deleted it from tmp folder?

So I tried to free up some space in nginx server and I deleted content of tmp files.
Then When i tried to run command:
sudo nginx -t -c /etc/nginx/nginx.conf
I got error:
sudo nginx -t -c /etc/nginx/nginx.conf
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2018/04/27 10:33:44 [emerg] 1580#1580: open() "/var/log/nginx/access.log" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
Is there anyway to recreate nginx.pid file?. I also created manually nginx/error.log file and gave them permissions chmod -R 777.
You could touch the files and then start again nginx, for example:
# touch /var/log/nginx/error.log
# touch /var/log/nginx/access.log
Test if your config just to verify and start again, the pid will be automatically created:
# nginx -t -c /etc/nginx/nginx.conf
From the command line example from the docs you could also do:
nginx -t -c /path/to/nginx.conf -g "pid /var/run/nginx.pid; worker_processes 2;"

nginx.conf and nginx.pid users and permissions

I'm embarking on watching my NGINX error.log files at level: warn... probably a silly idea and will cause me to crash my server as I work out any bugs happening, but hey, we're nerds and this is why we're here.
I'm noticing a [warn] and an [emerg] pop up every time I restart my server, which shows:
[warn] 8041#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
[emerg] 8041#0: open() "/run/nginx.pid" failed (13: Permission denied)
The top of my nginx.conf file reads:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
Which to me, shows me a few things.
I'm running NGINX with the user: www-data.
The number of worker processes that are allowed is automatically adjusted.
my PID file/information is being stored in /run/nginx.pid.
The error tells me that NGINX doesn't have permission to access /run/nginx.pid, which led me to see the user permissions for said file.
sudo ls -la /run/nginx.pid
reveals:
-rw-r--r-- 1 root root 5 Jun 18 05:34 /run/nginx.pid
Then trying:
ps -ef | grep nginx
produces:
root 5914 1 0 05:34 ? 00:00:00 nginx: master process /u
www-data 5917 5914 0 05:34 ? 00:00:00 nginx: worker process
scratches head
Now, can somebody out there tell me why, or how the hell NGINX has managed to create the master process with root ownership, and now the worker processes are owned by www-data?
Or more to the point, anybody have some suggestions on what to do about this [emerg] error I'm getting?
My first thought is to just try and change the ownership of the /run/nginx.pid file and see how NGINX likes it, but I kind of feel that even if I do that manually this time, when I restart the server, I'll run into the same problem.
My second thought is maybe there is somewhere else that I define my worker process initiation within NGINX..
Thanks.
EDIT
The contents of the /etc/systemd/system/multi-user.target.wants/nginx.service file are:
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/usr/sbin/nginx -s quit
[Install]
WantedBy=multi-user.target
I got the same error on my Centos 7 server today.
nginx.pid" failed (13: Permission denied)
For me, it turned out to be a problem with SELinux. I did the following to make it work again:
systemctl stop nginx
touch /var/run/nginx.pid
chcon -u system_u -t httpd_var_run_t /var/run/nginx.pid
systemctl start nginx
running
ls -Z nginx.pid
should output
-rw-r--r--. root root system_u:object_r:httpd_var_run_t:s0 nginx.pid
In my case I got a
"/usr/local/var/run/nginx.pid" failed (13: Permission denied)
bind() to 0.0.0.0:80 failed (48: Address already in use)
and the working solution was made up of these steps:
stop root process
sudo nginx -s stop
check if process stopped
ps aux | grep nginx
restart process
sudo nginx -s reload
gave me the error
nginx: [error] open() “/usr/local/var/run/nginx.pid” failed (2: No such file or directory)
probabil .pid was started with the wrong root user as I uncommented the line with path to .pid in /usr/local/etc/nginx/nginx.conf and then I commented it back again
to start nginx as a user and not root
brew services start nginx
result at running command
ps aux | grep nginx
youruser 89212 0.0 0.0 4268280 644 s002 S+ 2:46PM 0:00.00 grep nginx
youruser 89179 0.0 0.0 4302204 1776 ?? S 2:45PM 0:00.00 nginx: worker process
youruser 89178 0.0 0.0 4275372 4368 ?? S 2:45PM 0:00.01 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
And as it can be seen, the nginx process started with the expected user and not as root and the conflict between processes was gone and I could access the PHP application local domain.
For Ubuntu 20.04+
I got the exact same error while I was using sudo systemctl reload nginx
Using sudo service nginx restart instead throws no error

Why am I getting this Nginx error about "No such file or directory"?

I am trying to create a local pip2pi repo and then serve it up via Nginx. I have successfully created the repo and have all the wheel files I am wanting on my local machine. They are located like this:
/home/user/code/misc/pip-packs/simple
\
---index.html
--- amqp
\
-------- index.html
-------- amqp-1.4.6-py2-none-any.whl
--- django
\
-------- index.html
-------- Django-1.9.3-py2.py3-none-any.whl
... ETC
Now to serve the files I am using Nginx on docker, simply using the official Nginx docker image. I run the container like this:
docker run --name pypi-nginx -p 80:80 \
-v /home/user/code/misc/pip-packs/simple:/usr/share/nginx/html \
-d nginx
I can open localhost and see the index.html at root (/) and I can click on a link e.g. amqp and then get a link for the amqp-1.4.6-py2-none-any.whl file. When I click on the link I expect a download to initiate. Howver I get a 404 page from Nginx.
THe file is definitely there, as I can run:
docker exec -it pypi-nginx /bin/bash
And then ls and the /usr/share/nginx/html directory and see all the files from the voulume.
Further I can run pip install amqp-1.4.6-py2-none-any.whl on my local, so I know it's an actual wheel file.
Nginx's official log error is:
2016/05/20 14:48:01 [error] 7#7: *1 open() "/usr/share/nginx/html/funcsigs/funcsigs-0.4-py2.py3-none-any.whl" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /funcsigs/funcsigs-0.4-py2.py3-none-any.whl HTTP/1.1", host: "localhost", referrer: "http://localhost/funcsigs/"
but yet it serves the index files in each firectory. The nginx conf files I am using are the standard ones from the container. I can post those if necessary.
In the directory /home/user/code/misc/pip-packs/ is where pip2pi stores the packages it downloaded. So in /home/user/code/misc/pip-packs/ you have
/home/user/code/misc/pip-packs/
\
--- amqp-1.4.6-py2-none-any.whl
--- Django-1.9.3-py2.py3-none-any.whl
--- ETC
Then as in the simple directory as described in the question above, each repo folder supposedly has the wheel file as well, yet there was a 404. Well i glossed over the dir2pi pip-packs/ command, which only created symlinks and did not copy the wheel files. So when I mounted the volume to the container, the actual wheel files, that all the symlinks pointed to, never got copied to the container.
The output of 'ls -al' for the Django folder (packages/simple/django) is:
drwxr-xr-x 2 bdew70 bdew70 4096 May 20 11:02 .
drwxr-xr-x 64 bdew70 bdew70 4096 May 20 11:02 ..
lrwxrwxrwx 1 bdew70 bdew70 39 May 20 11:02 Django-1.9.3-py2.py3-none-any.whl -> ../../Django-1.9.3-py2.py3-none-any.whl
-rwxr-xr-x 1 bdew70 bdew70 88 May 20 11:02 index.html
The solution is to make a Dockerfile and then ADD the wheel files to the /user/share/nginx/ folder along with the html files to the /usr/share/nginx/html/ folder. The Dockerfile should look like this:
FROM nginx
ADD packages/simple /usr/share/nginx/html/
ADD packages /usr/share/nginx
The moral of the story is to use '-al' (or create an alias for ls) when investigating file problems and to be careful of symlinks in Docker container volumes. Especially if the symlink is relative and in the form ../../some-file.

/etc/init.d/nginx restart as root fails but nginx -t won't tell anything

So Nginx is started in daemon mode, but root, as confirms this command:
root#test:/home/vagrant# ps -edf | grep nginx
root 7331 1 0 13:42 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 7333 7331 0 13:42 ? 00:00:00 nginx: worker process
But if I:
root#test:/home/vagrant# /etc/init.d/nginx restart
* Restarting nginx nginx [fail]
But when I run:
root#test:/home/vagrant# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
It's only when I go back to user vagrant that I get:
[13:46:58] vagrant#test:/home/vagrant $ nginx -t
2016/04/21 13:47:01 [emerg] 7390#7390: open() "/run/nginx.pid" failed (13: Permission denied)
And if I:
root#test:/home/vagrant# ls -l /run/nginx.pid
-rw-r--r-- 1 root root 5 Apr 21 13:45 /run/nginx.pid
So why won't nginx restart? What am I doing wrong? I mean, root not having enough permission doesn't make sense, does it?
And how come sudo nginx -t doesn't display any error message?
Have you this directive in your configuration file user www www; ?
If yes, does the user www (or whom you set) have access to the pid file and to the site directories ?
extra: if you need you can move the pif file using the pid path; directive.

Resources