How to restart nginx on OS X

restart nginx ubuntu
restart nginx windows
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: no such file or directory)
stop nginx mac
install nginx mac without homebrew
os x nginx config files
nginx folder mac os x
mac nginx config

I'm using nginx on OS X 10.8. Freshly installed nginx but can't find a way to restart nginx except kill nginx_pid say kill 64116. Wondering if there are better ways to restart nginx.

Found some methods on Google and SO but didn't work:

nginx -s restart

sudo fuser -k 80/tcp ; sudo /etc/init.d/nginx restart

The error message for nginx -s restart is

nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

Sometimes also get this error msg:

nginx: invalid option: "-s restart"

What is your nginx pid file location? This is specified in the configuration file, default paths specified compile-time in the config script. You can search for it as such:

find / -name nginx.pid 2>/dev/null (must issue while nginx is running)

Solution:

sudo mkdir -p /usr/local/var/run/
ln -s /current/path/to/pid/file /usr/local/var/run/nginx.pid

How to restart Nginx on Mac OS X?, What is your nginx pid file location? This is specified in the configuration file, default paths specified compile-time in the config script. You can  To restart the nginx web server use any one of the following command as a root user as per your Linux distro. Open a terminal or login to the remote server using ssh. For instance: ssh vivek@server1.cyberciti.biz. sudo systemctl nginx [command]

Try running sudo nginx before starting nginx.

How to restart nginx on OS X, We will see how to install Nginx, PHP-FPM and MariaDB (MySQL) on macOS High Sierra thanks to Homebrew package manager. Ubuntu Linux restart nginx. Type the following command: sudo systemctl restart nginx OR sudo service nginx restart OR (older Ubuntu Linux version): sudo /etc/init.d/nginx restart. Start / Restart / Stop Nginx Commands. The same commands can be used to start / stop / restart the nginx server on a Ubuntu Linux. For example:

To reload config files:

sudo nginx -s reload

To fully restart nginx:

sudo nginx -s quit
sudo nginx

Details

There is no restart signal for nginx. From the docs, here are the signals that the master process accepts:

SIGINT, SIGTERM  Shut down quickly.
SIGHUP           Reload configuration, start the new worker process with a new configuration, and gracefully shut down old worker processes.
SIGQUIT          Shut down gracefully.
SIGUSR1          Reopen log files.
SIGUSR2          Upgrade the nginx executable on the fly.
SIGWINCH         Shut down worker processes gracefully.

Presumably you could send these signals to the process id manually, but the nginx command has the flag nginx -s <signal> that sends signals to the master process for you. Your options are:

stop    SIGTERM
quit    SIGQUIT
reopen  SIGUSR1
reload  SIGHUP

No need to futz with the pid manually.


Edit: just realized much of this info was already in comments on the other answers. Leaving this here anyway to summarize the situation.

Setting up a Nginx web server on macOS – Sylvain Durand, Nginx pronounced “engine x” is a free, open-source, high-performance HTTP and reverse proxy server responsible for handling the load of  How to Start, Stop, or Restart Nginx on FreeBSD Another option is to directly send signal to a master FreeBSD nginx process using the following syntax : # /usr/local/sbin/nginx -s [stop|quit|reopen|reload]

I do it like this:

First kill the progress

ps aux | grep nginx
kill -9 {pid}

Then start nginx

nginx

It works!

How to Start, Stop, or Restart Nginx, Explains how to restart nginx web server under any Linux distribution after making changes to nginx.conf file using command line options. Before start you should ensure that you have Command Line Tools installed in your mac. It is part of XCode. You should have it installed and updated. Install Command Line Tools if not exist. xcode-select --install. 1. xcode-select --install. Install Nginx using Homebrew. brew tap homebrew nginx brew install nginx.

Try this:

sudo nginx -s stop

followed by a:

sudo nginx

It seems that nginx keeps track of its state, to if you stop it twice, it will complain. But the above worked for me.

Linux Restart Nginx WebServer Command, When you need to start, stop or restart the Apache (httpd) service on Mac OS X. Renamed nginx. conf sudo nginx -t ng Jan 01, 2019 · Start a container run and  To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the “Server Events” tab. The native installer also includes a command-line script to start, stop and restart applications, named ctlscript.sh.

Stop and start nginx mac, Use brew to install the nginx with command: brew install nginx. After install run: sudo nginx. Testing. Open Navigator it by going to URL: To install and launch Nginx on startup, we use: brew install nginx sudo brew services start nginx Although we musn’t use sudo with brew install, it is necessary to use it to launch Nginx if we want to use the the default port 80.

Installing Nginx in Mac OS X Maverick With Homebrew, Reloading keeps the server running while re-reading any configuration file updates. Reloading is safer than restarting because if a syntax error  Installing nginx with homebrew is very easy on macOS X/Mojave. In this article we will cover nginx installation, configuration and start/stop.

How to reload and restart Nginx (Dedicated servers only , Use brew to install the nginx with command: brew install nginx. After install run: sudo nginx. Testing. Open Navigator it by going to URL: To restart nginx service, you'll need to use systemctl command line tool. It is recommended to check syntax before restarting nginx service, $ sudo nginx -t $ sudo systemctl restart nginx If you're restarting after modifying nginx service unit file, you need to reload systemd first

Comments
  • By running the above find command I found /usr/local/var/run/nginx.pid does exist. The error msg now is nginx: invalid option: "-s restart"
  • That's because it's not a valid signal. Check the man page (which you should always do, anyway): Send signal to a master process: stop, quit, reopen, reload.
  • It seems a better way to simulate restart is nginx -s stop; nginx
  • or nginx -s reload if you just need updating config
  • If youre looking for where nginx is, according to the docs its on one of three places, By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx. I found mine in /etc/nginx
  • nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] still could not bind()
  • @pinouchon i get the above. i want to stop and restart
  • i get this sudo nginx -s reload nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
  • This method doesn't work for me! I want to know what the meaning of 9?
  • Ironically sudo nginx fixes the issue. after that I was able to reload and run the server without any errors.
  • nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx.pid" ...
  • Would be helpful to show the code on how to kill those processes via command line.
  • This is a better solution than leaving symlinks behind in my opinion