Adminbuntu

Everything for the Ubuntu Server Administrator

User Tools

Site Tools


Sidebar

Server Administration


Server Applications


At the Command Line


Elsewhere


Copyright 2013 Applied Conscious Technologies, LLC

Terms of Agreement

Contact


submit to reddit

nginx

Nginx

Nginx community documentation: http://wiki.nginx.org/

Ubuntu community documentation: https://help.ubuntu.com/community/Nginx

Nginx news: http://nginx.org/

description: http://nginx.org/en/

commercial: http://nginx.com/

Nginx Virtual Server Setting up a virtual host, or server block in Nginx parlance.

Start, Stop, Restart, Reload Nginx

Start

sudo service nginx start

Stop

sudo service nginx stop

Restart

sudo service nginx restart

Reload

sudo nginx -s reload

Testing

Test Configuration

sudo nginx -t

Check Whether Nginx is Running

ps waux | grep nginx

or

pgrep nginx

Ubuntu Style Enable/Disable Site Scripts

project page: https://github.com/perusio/nginx_ensite

The a2ensite and a2dissite scripts for Apache are convenient. You can have this same convenience with nginx.

Installation

This will install the scripts with manuals and bash completion.

mkdir ~/src
cd ~/src
git clone https://github.com/perusio/nginx_ensite.git
cd nginx_ensite
sudo cp nginx_* /usr/bin
cd man
sudo cp nginx_* /usr/share/man/man8
cd ../bash_completion.d
sudo cp nginx-ensite* /etc/bash_completion.d/

Enable a Site

sudo nginx_enssite site-name-here

Disable a Site

sudo nginx_dissite site-name-here

Manually Enable/Disable Sites

If you don't install Ubuntu Style Enable/Disable Site Scripts you enable and disable sites by adding or removing a symbolic link to /etc/nginx/sites-enabled.

Enable a Site

Create a symbolis link in sites-enabled to the configuration file in sites-available.

ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/mysite

Disable a Site

Remove the symbol link.

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

Configure Nginx

sudo vi /etc/nginx/nginx.conf

Logging

Access Log

Use the access_log directive in the http block of /etc/nginx/nginx.conf.

http{
  access_log /var/log/nginx/access.log combined;
}

To turn access logging off, use 'access_log off'.

http{
  access_log off;
}

Error Log

Use the access_log directive in /etc/nginx/nginx.conf.

error_log  /var/log/nginx/error.log;

Problem Solving

Could not Restart nginx

nginx got into a state where it could not be re-started. It was erroring with this in the error log:

bind() to 0.0.0.0:80 failed (98: Address already in use)

The command:

sudo netstat -taupen

Showed that only nginx was bound to port 80. And:

pgrep nginx

Showed several nginx instances running even after I had used:

sudo service nginx stop

This is what fixed it:

sudo service nginx stop
sudo killall nginx
sudo service nginx start

After that, nginx responded normally to the restart command.

nginx.txt · Last modified: 2016/06/10 17:42 by andrew