Skip to content

Installation

shell
sudo apt update
sudo apt install nginx

Config file

This is a simplified example, please refer nginx full example for more details.

Use nginx -t -c <config.file> to test the configuration file and fix error.

txt
pid     /nginx-install-dir/nginx.pid;
events {
  worker_connections  1024;  ## Default: 1024
}
http {
    include mime.types;
    log_format   main '$remote_addr - $remote_user [$time_local]  $status '
      '"$request" $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /nginx-install-dir/log/access.log;
    error_log /nginx-install-dir/log/error.log;
    server {
        listen 80;
        server_name _;
        return 301 https://$host$request_uri;
    }
    server {
        listen              443 ssl;
        ssl_certificate     /nginx-install-dir/certs/ennkee.com_bundle.crt;
        ssl_certificate_key /nginx-install-dir/certs/ennkee.com.key;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
        server_name   ennkee.com www.ennkee.com;
        error_log     /nginx-install-dir/log/error.log;
        error_page    404    /data/www/404.html;

        location / {
            root /data/www;
            index index.html index.htm;
        }
    }
}

Setup scripts for start/stop/query

shell
# start.sh
/usr/sbin/nginx -c <config.file>

# stop.sh
/usr/sbin/nginx -c <config.file> -s stop

Reference