Stopped Nginx still allows root index.html access - nginx

I'm brand new to Nginx. But after running
sudo /etc/init.d/nginx stop
and got
Stopping nginx: [OK]
I can still browser index.html from outside ip.
How can I really/completely stop Nginx server? Thanks a lot!

sudo /etc/init.d/nginx stop
will do the trick

Related

nginx config does not update after reload

following this tutorial :
https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-centos-7
I modified my config file /etc/nginx/sites-available/domainName by adding on the last row :
return 301 $scheme://www.example.com$request_uri;
Then I launched :
sudo systemctl restart nginx
It works well. Then I tried to modify www.example.com by my domain name and I launched again ;
sudo systemctl restart nginx
but it doesn't work, I'm still redirecting to example.com
I checked the log files, sudo nginx -t etc and everything looks good.
Do you have an idea of the problem?
Thanks
Try clearing the DNS cache in your pc, browser, and router.
If you're using Windows to run a Linux server in a virtual box, you can run the ipconfig /displaydns command to see the time of cache to live.

How to reload nginx in windows

I have installed nginx as a load balancer on my Windows machine using nssm. Now, I want to reload the configuration file of nginx for that I used nginx -s reload command but it is not working. It gives errors as access denied and I don't want to restart nginx. Is there any way to reload the nginx configuration file in windows.
Try following:
nssm restart nginx

Engintron: Nginx couldn't start

I have a Cpanel/WHM server with Nginx installed as reverse proxy (with default Nginx manager), so i tried to replace Nginx with Engintron.
I installed Engintron and uninstalled Nginx via Cpanel Nginx manager.
As a result i got website not working and Nginx couldn't start (status from WHM Engintron page), so i should reinstall Nginx?
I don't know if Engintron contains already Nginx or not
I tried to reinstall Nginx and website work again, but i don't know if Engintron is serving the website or Nginx
Engintron contains nginx installation within their script. So if you install only engintron, it will be default instead nginx in reverse proxy mode with apache.
You can check your nginx installed configuration file location by
sudo nginx -t
(it will show location of configuration file along with testing the same).
See if the nginx configuration file matches the engintron configuration file or not. If you are confused here also then run
$ sudo nginx -T
this will dump the output of configuration file which you may tally with Engintron config file.
Last option would be to uninstall both the nginx and make a clean installation of Engintron.
Try to run these commands first:
/usr/sbin/nginx -s stop
/usr/local/cpanel/scripts/restartsrv_nginx start
If the problem still exists, Uninstall Nginx and all Ruby packages from EasyApache via WHM and reinstall Nginx again.

Nginx.pid Permission Denied

I am using nginx through brew and it appears to be configured and working correctly - to a point. I have multiple host files (around 20 sites) and almost all of them work fine, however, any new sites added will not work.
All old host files seem to load just fine, for example with server name site.test on port 80, but any new host files added return with a "Server not found" in my web browsers.
After much troubleshooting and Google searching, I've finally found something that seems odd in my setup and it was this post that triggered it: nginx.conf and nginx.pid users and permissions. Although it doesn't seem to solve my exact problem.
When I run nginx -t I get:
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:1
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
However, when I run sudo nginx -t I get:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
I have both killed nginx and stopped it gracefully with brew and restarted it with sudo, but I appear to get the same issue with nginx.pid.
When I start nginx, I use: sudo brew services start nginx
Running ps aux | grep nginx, returns:
Media32 7444 0.0 0.0 4339424 2016 ?? S 12:16pm 0:00.01 nginx: worker process
Media32 7443 0.0 0.0 4339424 1836 ?? S 12:16pm 0:00.00 nginx: worker process
root 7440 0.0 0.0 4297440 4876 ?? Ss 12:16pm 0:00.01 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
Which should be correct as my user is setup in nginx.conf to be user Media32 staff.
I can provide any other code necessary, but I have been at a bit of a loss for days on this now and any help would be appreciated.
Update
I appear to have solved this by editing /etc/hosts and adding a record for the new host files, ie. 127.0.0.1 site.test and then after reloading nginx it worked, but I have never had to do this before, can anyone shed any light on why this is needed and wasn't needed prior?
I have solved this issue in macOS Catalina.
sudo brew services stop nginx
sudo chmod 777 /usr/local/var/run/nginx.pid
sudo brew services start nginx
nginx -t
Apart from the fact that setting any new host in /private/etc/hosts as
127.0.0.1 mysite.test
is a rule when adding a new host domain locally,
In my case I got a
the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:2
"/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.
Make sure you're running nginx -t as the root user using "sudo nginx -t" since the configuration checker requires root permissions.
(This solved the problem for me)

nginx virtual host - fail when restart with no error

I have several subdomains running on nginx, and when i added next one, there was a problem with the same name of subdomain i removed.
I'm not shure that config were worked in the past. This is what i have found on serwer.
For now there is no possibility to restart nginx with virtual hosts, becouse it's failed.
config tests is ok,
without vh's it is restarting well,
nginx.conf test is ok,
logs are clear
nginx config is placed in project and /etc/nginx is pointing to that folder
I have add that exaple vh and it is crushing event with it.
What else can i check, what may cause such a problem?
I have found solution. Nginx could not start after stop, becouse ports 80 and 433 were busy by... nginx. Anyway
netstat -tulpn
shown what process are runing on particular ports.
I killed these processes with commands:
sudo fuser -k 80/tcp and fuser -k 433/tcp
and after that
sudo service nginx start
just worked.
Config files are fine, and test pass, logs where clear and nginx command show whats wrong

Resources