Nginx

Modified: 22 Apr 2016 14:02 UTC

The Joyent Nginx images is a SmartOS base64 image pre-configured with Nginx, a high performance web and proxy server.

You can find more information about Nginx at their website.



Overview

Nginx comes pre-installed and tuned according to your VM size under the www user as the SMF service svc:/pkgsrc/nginx:default. The instance also comes pre-configured with a virtual host listening on all interfaces with PHP support.

Directory layout

The directory and file layout is as follows:

Directory/File Description
/opt/local/sbin Holds Nginx server binaries
/opt/local/etc/nginx The configuration directory for Nginx
/opt/local/etc/nginx/virtualhosts The virtual hosts configuration directory for Nginx
/var/log/nginx Where Nginx access and error logs are kept
/var/log/php-fpm.log Log file for php-fpm
/home/admin/web/public Docroot for the default virtual host

Starting Nginx

By default nginx comes enabled. You can disable, restart the service with:

    # svcadm disable pkgsrc/nginx

or restart:

    # svcadm restart pkgsrc/nginx

To check the status of the service:

    # svcs pkgsrc/nginx
    online         May_12   svc:/pkgsrc/nginx:default

Configuration

The Nginx configuration files are stored at /opt/local/etc/nginx and virtual host files at /opt/local/etc/nginx/virtualhosts.

Virtual hosts

Default virtual host

By default the instance comes pre-configured with a virtual host listening on all interfaces. The configurations for these are at /opt/local/etc/nginx/virtualhosts/<x.x.x.x>.conf with docroot directory /home/admin/web/public. If this configuration works for you (behind a load balancer) then you can just drop in your static files there.

Create a virtual host with sm-create-vhost

To add a new virtual host you can enter one in manually in the configuration directory (/opt/local/etc/nginx/virtualhosts) or use the sm-create-vhost helper script which comes in the smtools package.

Creating a new virtual host with sm-create-vhost:

    # sm-create-vhost nginx example.com /home/admin/web/example.com
    * Created /opt/local/etc/nginx/virtualhosts directory.
    * Created Nginx configuration /opt/local/etc/nginx/virtualhosts/example.com.conf.
      Settings:
        Hosts:   example.com *.example.com www.example.com
        Port:    80
        Docroot: /home/admin/web/example.com

      For changes to take you will need:

      include /opt/local/etc/nginx/virtualhosts/*;

      in your /opt/local/etc/nginx/nginx.conf http{} block and restart nginx with
      svcadm restart pkgsrc/nginx.

      If you want PHP support with nginx you will need to
      svcadm enable svc:/pkgsrc/php-fpm.

All virtual hosts come with PHP support as long as php-fpm is enabled.

Memory usage

Monitoring the processes memory usages is easy with project support.

Nginx memory usage can be monitored under the nginx project using prstat -J. PHP memory usage can also be monitored this way under the php project.

    # prstat -J
    PROJID    NPROC  SWAP   RSS MEMORY      TIME  CPU PROJECT
         0       16   72M   44M   0.0%   0:00:58 0.0% system
       925        2   18M 5548K   0.0%   0:00:00 0.0% nginx
       926        3   68M 9876K   0.0%   0:00:00 0.0% php

DTracing Nginx

The dtracetools package comes with a Nginx sample script dtrace-nginx_reqsec.d to show req/sec. Run it with -p specifying the pid of the nginx process.

    # dtrace-nginx_reqsec.d -p <pid of nginx>

You can view Nginx function entry and return points with the one-liner:

    # dtrace -Fn 'pid$target:nginx::entry { } pid$target:nginx::return {}' -p <pid of nginx>
    dtrace: description 'pid$target:nginx::entry ' matched 2460 probes
    CPU FUNCTION
     21  -> ngx_time_update
     21    -> ngx_gmtime
     21    <- ngx_gmtime
     21    -> ngx_sprintf
     21      -> ngx_vslprintf
     21        -> ngx_sprintf_num
     21        <- ngx_sprintf_num
     21        -> ngx_sprintf_num
    ...

You can view Nginx file opens with this one-liner:

    # dtrace -n 'pid$target::open*:entry { trace(copyinstr(arg0)) }' -p <pid of nginx>
    dtrace: description 'pid$target::open*:entry ' matched 14 probes
    CPU     ID                    FUNCTION:NAME
      9  69701                       open:entry   /opt/local/share/examples/nginx/html/test.html

Version 15.x.x

15.4.1

Name nginx
Description A SmartOS 64-bit image pre-configured and optimized as a Nginx 1.9.5 server. Comes packaged with a default virtual host listening on all int
erfaces.
UUID 2d7ec6d2-f100-11e5-84d7-77c57246a64a
Based on base-64-lts 15.4.1
Pkgsrc 2015Q4
What's New In This Image
Software Included In This Image

Software installed as pkgsrc packages:

bzip2-1.0.6nb1       Block-sorting file compressor
curl-7.47.1          Client that groks URLs
db4-4.8.30           Berkeley DB version 4 from Oracle
dtracetools-0.7nb20160127 DTraceTools for Joyent SmartMachines
gcc47-libs-4.7.4nb1  The GNU Compiler Collection (GCC) support shared libraries
gcc49-libs-4.9.3nb1  The GNU Compiler Collection (GCC) support shared libraries
gtar-base-1.28nb1    The GNU tape archiver with remote magnetic tape support
htop-1.0.1nb1        Enhanced version of top utility
nginx-1.9.5nb1       Lightweight HTTP server and mail proxy server
nodejs-5.7.0         V8 JavaScript for clients and servers
openssl-1.0.2g       Secure Socket Layer and cryptographic library
perl-5.22.0          Practical Extraction and Report Language
php-5.6.19           PHP Hypertext Preprocessor version 5.6
php56-fpm-5.6.19nb1  FPM interface for PHP5.6
pkgin-0.9.4          Apt / yum like tool for managing pkgsrc binary packages
postfix-3.0.2nb2     Postfix SMTP server and tools
python27-2.7.11      Interpreted, interactive, object-oriented programming language
smtools-20160316     Joyent tools relevant to SmartOS and SmartMachines
sqlite3-3.9.2        SQL Database Engine in a C Library
sudo-1.8.15          Allow others to run commands as root
wget-1.17.1          Retrieve files from the 'net via HTTP and FTP
zoneinit-1.6.8       Joyent Instance initialization toolchain

Software installed as npm packages:

json@9.0.3
manta@2.0.5
smartdc@8.1.0

15.1.1

Name nginx
Description A SmartOS 64-bit image pre-configured and optimized as a Nginx 1.7.10 server. Comes packaged with a default virtual host listening on all interfaces.
UUID db47466e-0889-11e5-a4d0-77947c5b8b70
Based on base-64 15.1.1
Pkgsrc 2015Q1

What's New In This Image

Software Included In This Image

Software installed as pkgsrc packages:

bzip2-1.0.6nb1
curl-7.42.0
db4-4.8.30
dtracetools-0.7
gcc47-libs-4.7.4nb1
gtar-base-1.28nb1
htop-1.0.1
nginx-1.7.10
nodejs-0.12.4
openssl-1.0.2a
perl-5.20.2
php-5.5.25
php55-fpm-5.5.25
pkgin-0.8.0
postfix-2.11.4
python27-2.7.9nb1
smtools-20150312
sqlite3-3.8.10
sudo-1.7.10p9
wget-1.16.3
zoneinit-1.6.8

Software installed as npm packages:

json@9.0.3
manta@1.5.1
smartdc@7.3.1

Version 14.x.x

14.4.0

Name nginx
Description A SmartOS 64-bit image pre-configured and optimized as a Nginx 1.7.4 server. Comes packaged with a default virtual host listening on all interfaces.
UUID d53928c8-d260-11e4-8f38-a70310430fdb
Based on base-64-lts 14.4.0
Pkgsrc 2014Q3
What's new in this image
Software included in this image

Software installed as pkgsrc packages:

bzip2-1.0.6nb1
curl-7.39.0nb1
db4-4.8.30
dtracetools-0.7
gcc47-libs-4.7.3nb7
gtar-base-1.28
htop-1.0.1
nginx-1.7.4
nodejs-0.12.0
openssl-1.0.1k
perl-5.20.1
php-5.5.22
php55-fpm-5.5.22
pkgin-0.7.0
postfix-2.11.3
python27-2.7.9
smtools-20150226
sqlite3-3.8.7.4
sudo-1.7.10p9
wget-1.16.1
zoneinit-1.6.8

Software installed as npm packages:

json@9.0.3
manta@1.5.1
smartdc@7.3.1

14.3.0

Name nginx
Description A SmartOS 64-bit image pre-configured and optimized as a Nginx 1.7.4 server. Comes packaged with a default virtual host listening on all interfaces.
UUID f9da09c6-7a55-11e4-b5eb-d37be7980fa0
Based on base64 14.3.0
Pkgsrc 2014Q3
What's new in this image
Software included in this image

Software installed as pkgsrc packages:

    bzip2-1.0.6nb1
    curl-7.38.0
    db4-4.8.30
    gcc47-libs-4.7.3nb7
    gtar-base-1.28
    nginx-1.7.4
    nodejs-0.10.33
    openssl-1.0.1j
    perl-5.20.0nb2
    php-5.5.18
    php55-fpm-5.5.18
    pkgin-0.6.4nb7
    postfix-2.11.1nb1
    python27-2.7.8nb1
    smtools-20141114
    sqlite3-3.8.6
    sudo-1.7.10p8
    wget-1.16
    zoneinit-1.6.8

Software installed as npm packages

manta@1.4.5
smartdc@7.3.0

14.2.0

Name nginx
Description A SmartOS 64-bit image pre-configured and optimized as a Nginx 1.6.0 server. Comes packaged with a default virtual host listening on all interfaces.
UUID 83565bea-27a5-11e4-bfd0-b7aa35497452
Based on base64 14.2.0
Pkgsrc 2014Q2
What's new in this image
Software included in this image

Software installed as pkgsrc packages:

    bzip2-1.0.6nb1
    curl-7.37.0nb1
    db4-4.8.30
    gcc47-libs-4.7.3nb4
    gtar-base-1.27.1nb1
    libarchive-2.8.4nb4
    nginx-1.6.0
    nodejs-0.10.30
    openssl-1.0.1h
    perl-5.20.0nb1
    php-5.5.14nb1
    php55-fpm-5.5.14
    pkgin-0.6.4nb7
    postfix-2.11.1nb1
    python27-2.7.7nb2
    smtools-20140728
    sqlite3-3.8.5
    sudo-1.7.10p8
    wget-1.15nb2
    zoneinit-1.6.8

Software installed as npm packages

    jsontool@7.0.2
    manta@1.4.2
    smartdc@7.3.0

14.1.0

Name nginx
Description A SmartOS 64-bit image pre-configured and optimized as a Nginx 1.5.12 server. Comes packaged with a default virtual host listening on all interfaces.
UUID 4b348706-e122-11e3-9cb4-9b2c5062255c
Based on base64 14.1.0
Pkgsrc 2014Q1
What's new in this image
Software included in this image

Software installed as pkgsrc packages:

    bzip2-1.0.6nb1
    curl-7.36.0
    db4-4.8.30
    duo-unix-1.9.7
    gcc47-libs-4.7.3nb3
    gtar-base-1.27.1nb1
    nginx-1.5.12nb3
    nodejs-0.10.28
    openssl-1.0.1g
    perl-5.18.2nb1
    php-5.5.10nb2
    php55-fpm-5.5.10
    pkgin-0.6.4nb5
    postfix-2.11.0nb1
    python27-2.7.6nb3
    smtools-20140509
    sqlite3-3.8.4.1
    sudo-1.7.10p8
    wget-1.15nb1
    zoneinit-1.6.7

Software installed as npm packages

    jsontool@7.0.2
    manta@1.2.7
    smartdc@7.2.1