How to run nginx on Foreground?

How to run nginx on Foreground?

By default, when you start nginx service it will start in self-daemonize mode, that mean nginx will run on background. If you’re planning to use nginx as a frontend to one or more app processes, it can be helpful to setup and test things locally. An easy way to do this is to run nginx in the foreground so you can quickly iterate your config options to see what works. Like all well-behaved programs, Nginx can be configured not to self-daemonize. Nginx uses the “daemon off” directive to run in the foreground.

Disable daemon mode in configuration

Your nginx configuration should contain following directive

1 2 3   daemon off;  

Sample config below

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16   # nginx.conf   worker_processes 1; daemon off;   events { worker_connections 2048; }   http { server { listen 80; } }  

If it’s inconvenient to put this in the configuration file, we can specify it directly on the command line

You can start nginx on foreground, using below command

1 2 3   nginx g ‘daemon off;’  

 

Author: , 0000-00-00