linux_wiki:nginx_http_server

This is an old revision of the document!


Nginx HTTP Server

General Information

Installation and configuration of Nginx web server.

Checklist

  • Distro(s): Enterprise Linux 6/7

Installation

Installation of Nginx can be completed via repo (Official Nginx, EPEL, or Software Collections) or compiling.

Nginx.org has pre-built packages. You can select mainline (newer) or stable.

Versions as of 04/13/2016:

  • Mainline: 1.9.14
  • Stable: 1.8.1
  • Legacy: 1.6.3 and below
  1. Add a nginx repo file
    • Stable Repo:
      vim /etc/yum.repos.d/nginx.repo
      [nginx]
      name=nginx repo
      baseurl=http://nginx.org/packages/centos/7/$basearch/
      gpgcheck=0
      enabled=1
    • Mainline Repo:
      vim /etc/yum.repos.d/nginx.repo
      [nginx]
      name=nginx repo
      baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
      gpgcheck=0
      enabled=1
  2. Install
    yum install nginx

Versions as of 04/13/2016

  • CentOS 7.2: Nginx 1.6.3

Procedure

  • Install the EPEL repo
  • Install Nginx
    yum install nginx

Versions as of 04/13/2016:

  • nginx 1.4 (legacy)
  • nginx 1.6 (legacy)
  • nginx 1.8 (stable)
  1. Install
    yum install rh-nginx18
  2. Enable the software collection
    scl enable rh-nginx18 bash
    1. Run signal commands (nginx -s signal) as normal from the Operation section below

Building from source is usually done for specific functionality and is more time consuming.

  1. Install pre-reqs
    yum install gcc pcre-devel zlib-devel
  2. Download a tarball (Example: Stable)
    wget http://nginx.org/download/nginx-1.8.1.tar.gz
  3. Unarchive/unpack
    tar -zxvf nginx-1.8.1.tar.gz
  4. Change into directory
    cd nginx-1.8.1/
  5. Configure nginx
    ./configure --prefix=/usr/local/nginx
    1. Available configuration options: http://nginx.org/en/docs/configure.html
  6. Compile
    make
  7. Install
    make install

Configuration

  • Main Config: /etc/nginx/nginx.conf
    • Alt Main (Compiled): /usr/local/nginx/conf/nginx.conf
  • Additional Config: /etc/nginx/conf.d/
    • Alt Additional Config (Compiled): No default

Operation

Controlling the nginx web server.

Nginx can be controlled via the system's service commands or nginx executable signals.

  • Main nginx executable: /usr/sbin/nginx
    • Alt main nginx executable (Compiled): /usr/local/nginx/sbin/nginx

  • Autostart the nginx web server upon system startup
systemctl enable nginx

  • Evaluate config files; if syntax is ok, start
systemctl start nginx

or

nginx

  • Stop the nginx processes now
  • Kills current sessions
systemctl stop nginx

or

nginx -s stop

  • Equivalent to Apache httpd's “graceful” restart
  • Check syntax
    • if ok, then spawn new workers with new config and signal old workers to shutdown after current requests are complete
    • if NOT ok, continue using old configuration
systemctl reload nginx

or

nginx -s reload

  • Kill worker processes immediately
systemctl restart nginx

  • Equivalent to Apache httpd's “graceful-stop”
  • Wait for worker processes to finish serving current requests, then stop.
  • Do not accept new requests
nginx -s quit

  • linux_wiki/nginx_http_server.1460604273.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)