No nginx folders after installing on Amazon Linux 2 EC2 instance - nginx

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?

Related

add Nginx 1.20.1 GeoIP2 module

I'm trying to configure nginx to build the GeoIP2 module, by following this installation:
https://github.com/leev/ngx_http_geoip2_module
first I still didn't understand what is defrences between static and dynamic modules,
and why can't I just apt install that module..
The problemm is that I want to build/create it on a diffrent machine, so I had to copy the configure flags from the destination machine by copy the output of this command:
nginx -V
and then I ran this command on the test machine:
PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/" ./configure --without-http_rewrite_module --without-http_gzip_module --add-module=/path/ngx_http_geoip2_module-3.3 (PASTE DESTINATION NGINX -V OUTPUT)
make
make install
Then after succession I copied the file name: ngx_http_geoip2_module.so to destination machine
and ran nginx -t
I got this error:
nginx: [emerg] module "/etc/nginx/modules/ngx_http_geoip2_module.so" is not binary compatible in /etc/nginx/nginx.conf
nginx: configuration file /etc/nginx/nginx.conf test failed
My destination machine:
Ubuntu 20
Nginx 1.20.1
--with-compat --add-module=/path/to/ngx_http_geoip2_module
or
--with-compat --add-dynamic-module=/path/to/ngx_http_geoip2_module

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;"

Install of openresty : nginx.pid not found

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.

"configuration file /etc/nginx/nginx.conf test failed": How do I know why this happened?

I'm an nginx noob trying out this this tutorial on nginx 1.1.19 on ubuntu 12.04. I have this nginx config file.
When I run this command the test fails:
$ sudo service nginx restart
Restarting nginx: nginx: [crit] pread() "/etc/nginx/sites-enabled/csv" failed (21: Is a directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
How do I know why the nginx.conf test failed?
sudo nginx -t should test all files and return errors and warnings locations
This particular commands worked for me.
sudo apt-get remove --purge nginx nginx-full nginx-common
and
sudo apt-get install nginx
credit to this answer on stackexchnage
The first solution is to test nginx conf using the basic
sudo nginx -t
Secondly, if you've changed the file yourself, copy/pasted json from one to another, there's a high chance that there's an encoding issue.
For example: " is not the same as
``
Try to write configurations by yourself. Check commas, colon and braces. Don't forget to reload the nginx.
sudo systemctl reload nginx
If you want to check syntax error for any nginx files, you can use the -c option.
[root#server ~]# sudo nginx -t -c /etc/nginx/my-server.conf
nginx: the configuration file /etc/nginx/my-server.conf syntax is ok
nginx: configuration file /etc/nginx/my-server.conf test is successful
[root#server ~]#
Show file and track error
systemctl status nginx.service

Nginx Invalid PID number

I issued a nginx -s stop and after that I got this error when trying to reload it.
[error]: invalid PID number "" in "/var/run/nginx.pid"
That /var/run/nginx/pid file is empty atm.
What do I need to do to fix it?
nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don't have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)
in my case I solved this by starting the service.
sudo /etc/init.d/nginx start
The command above will start the service in Debian/Ubuntu. It will issue an error if there is any problem (like Apache listening in the same port)
After that nginx -s reload will work like a charm
This will clear out the issue on ubuntu 16.04 and above
sudo service nginx stop
you may need to remove the pid file nginx.pid whose location may be defined in file /etc/nginx/nginx.conf look for line like
cat /etc/nginx/nginx.conf | grep pid # see if pid file is defined
this line may live in file /etc/nginx/nginx.conf
pid /run/nginx.pid; # in file /etc/nginx/nginx.conf
if pid file does exist then remove it now
ls -la /var/run/nginx/pid # this file may live elsewhere
ls -la /run/nginx.pid # on Ubuntu 16.04+
after the pid file has been removed lets launch nginx
sudo service nginx start
ps -eaf|grep nginx # confirm its running
sudo nginx -t && sudo nginx -s reload # confirm config is OK
# typical output
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo service nginx stop # issue stop
ps -eaf|grep nginx # confirm it actually stopped
now sanity has been restored and you are free to launch at will
In the latest version(1.2.0) that I downloaded there is no "-s start" option, it will say
nginx: invalid option: "-s start"
You can start nginx by
sudo /etc/nginx/sbin/nginx
The server will be started and then there wont be any Invalid pid number errors.
To avoid downtime with restarting nginx,
ps aux | grep nginx
PID of nginx master process
echo PID > /var/run/nginx.pid
nginx -s reload
In my case nginx was stopped (crashed I assume). Solved the issue by:
service nginx status
nginx stop/waiting
service nginx start
nginx start/running, process 3535
Then nginx -s reload worked like a charm.
I am using nginx/1.8.0 on trusty.
This happens if the nginx process was stopped manually or was killed.
Check if the process is still running:
sudo lsof -nP -iTCP:<port> | grep LISTEN
I am on mac, and I reinstall the nginx with:
brew reinstall nginx
Then start the service using brew:
brew services start nginx
On CentOS 7 I done it with this:
sudo systemctl start nginx
#Then check all things are OK
sudo systemctl status -l nginx
For anyone who still has issues, in my case, there was an apache2 server that was running.
You can try debugging what went wrong in your nginx machine by executing this command -
systemctl status nginx
This gave me an insight that the port was already in us by apache2 server.
so you can do sudo service apache2 stop and then do sudo service nginx start.
Docker Alpine users should use
nginx
by using that nginx will be start there is no error by
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
then reload it by
nginx -s reload

Resources