Skip to content

These list of Nginx commands should help you better understand and manage Nginx commands based on their functionality.

Notifications You must be signed in to change notification settings

mnestorov/nginx-commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 

Repository files navigation

Nginx Commands

Licence

Overview

These list of Nginx commands should help you better understand and manage Nginx commands based on their functionality.

Starting and Stopping Nginx

Configuration Management

Logging and Monitoring

Process Management

Boot Configuration

Help and Version Information

Configuration File Management


Starting and Stopping Nginx

Start Nginx

sudo nginx

For systemd (Ubuntu 16.04 LTS and above):

sudo systemctl start nginx

Stop Nginx

Stopping Nginx will kill all system processes quickly. This will terminate Nginx even if there are open connections. In order to do so, run one of the following commands:

sudo nginx -s stop

For systemd (Ubuntu 16.04 LTS and above):

sudo systemctl stop nginx

Restart Nginx

sudo service nginx restart

For systemd (Ubuntu 16.04 LTS and above):

sudo systemctl restart nginx

Reload Nginx

sudo nginx -s reload

For systemd (Ubuntu 16.04 LTS and above):

sudo systemctl reload nginx

Quit Nginx

sudo nginx -s quit

Check Nginx status

sudo service nginx status

For systemd (Ubuntu 16.04 LTS and above):

sudo systemctl status nginx

Configuration Management

Reload Nginx configuration

sudo nginx -s reload

For systemd (Ubuntu 16.04 LTS and above):

sudo systemctl reload nginx

Test Nginx configuration for syntax errors

sudo nginx -t

Start Nginx with a custom configuration file

sudo nginx -c /path/to/custom/nginx.conf

Start Nginx with a custom error log file

sudo nginx -e /path/to/custom/error.log

Start Nginx with a custom global configuration prefix

sudo nginx -p /path/to/custom/prefix

Set a custom worker process count

sudo nginx -g "worker_processes COUNT;"

Logging and Monitoring

View Nginx error logs

sudo tail -f /var/log/nginx/error.log

View Nginx access logs

sudo tail -f /var/log/nginx/access.log

Display active Nginx connections

sudo nginx -V 2>&1 | grep -o with-http_stub_status_module

Process Management

Display Nginx process ID (PID)

sudo cat /run/nginx.pid

Send a signal to a specific Nginx process

sudo kill -s SIGNAL PID

Boot Configuration

Enable Nginx auto-start at boot

sudo systemctl enable nginx

Disable Nginx auto-start at boot

sudo systemctl disable nginx

Help and Version Information

Display Nginx version and configuration options

nginx -V

Display help information

nginx -h

Configuration File Management

Create a temporary backup of the Nginx configuration

sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup

Restore a backup of the Nginx configuration

sudo cp /etc/nginx/nginx.conf.backup /etc/nginx/nginx.conf

Open the main Nginx configuration file with a text editor

sudo nano /etc/nginx/nginx.conf

Open a specific server block configuration file with a text editor

sudo nano /etc/nginx/sites-available/your_server_block

Create a symbolic link to enable a server block

sudo ln -s /etc/nginx/sites-available/your_server_block /etc/nginx/sites-enabled/

Remove a symbolic link to disable a server block

sudo rm /etc/nginx/sites-enabled/your_server_block

License

This repository is unlicense[d], so feel free to fork.

About

These list of Nginx commands should help you better understand and manage Nginx commands based on their functionality.

Topics

Resources

Stars

Watchers

Forks