Reputation: 111
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?
Upvotes: 11
Views: 15333
Reputation: 311
here only works stopping the php and running the specific version with brew:
sudo brew services restart nginx && sudo brew services stop php && sudo brew services restart [email protected]
Upvotes: 0
Reputation: 31
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)
Upvotes: 1
Reputation: 16297
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
Upvotes: 8
Reputation: 183
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.
Upvotes: 0