Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homebrew Nginx not running but says it is in brew services

I have OSX El Capitan. I installed Nginx-Full via homebrew. I am supposed to be able to start and stop services with

brew services Nginx-Full Start

I run that command and it seems to start no problem. I check the running services with

brew services list

That indicates that the Nginx-Full services is running. When i run

htop

to look at everything that is running Nginx does not show up and the server is not handling requests.

like image 497
Dblock247 Avatar asked Jun 26 '16 16:06

Dblock247


People also ask

How do I know if nginx is running on my Mac?

Check Nginx is running or not We can verify that the Nginx is installed and running by using the following command: $ ps -ef | grep nginx.

Where does brew install nginx?

nginx will load all files in $(brew --prefix)/etc/nginx/servers/.

Where is nginx installed on Mac?

The Nginx server will install on the location /usr/local/cellar. The entire executable services related to starting and stopping Nginx are stored inside the bin folder of the installation directory.


3 Answers

nginx is failing to launch because of an error, but brew-services is not communicating that to you.

Running it with sudo, as other users have suggested, is just masking the problem. If you just run nginx directly, you may see that there is actually a configuration or permissions issue that is causing nginx to abort. In my case, it was because it couldn't write to the error log:

nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)
2020/04/02 13:11:53 [warn] 19989#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:2
2020/04/02 13:11:53 [emerg] 19989#0: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)

The last error is causing nginx to fail to launch. You can make yourself the owner of the logs with:

sudo chown -R $(whoami) /usr/local/var/log/nginx/

This should cause subsequent config errors to be written to the error log, even if homebrew services is not reporting them in stderr/stdout for now.

I've opened an issue about this: https://github.com/Homebrew/homebrew-services/issues/215

The log path may not the same for everyone. You can check the path to log file by checking the config file /usr/local/etc/nginx/nginx.conf. You can find a line like: error_log /Users/myusername/somepath/nginx.log;. Change the chown command above accordingly. If even this didn't solve the problem, you may have to do the same for any other log files specified in the server blocks in your nginx configuration

like image 108
alexw Avatar answered Oct 23 '22 17:10

alexw


Try launching it with "sudo", even if the formula say

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo.

sudo brew services Nginx-Full start
like image 44
Gounlaf Avatar answered Oct 23 '22 19:10

Gounlaf


this worked for me:

sudo brew services start nginx

like image 2
Emmanuel Avatar answered Oct 23 '22 17:10

Emmanuel