NGINX Commands (Ubuntu)

By James Kenny
1 min read

Table of Contents

A short guide of commands I've found myself using on Ubuntu for NGINX, I'll update this post as I find more.

Installing NGINX

sudo apt-get update

sudo apt-get install nginx

Restarting NGINX

To restart NGINX

sudo systemctl restart nginx

To just reload the NGINX

nginx -s reload

This will reload the NGINX config and any changes you make to it.

NGINX Config

A Sample Config for one of my static sites.

server {
  listen 80;

  listen [::]:80;

  root /var/www/jameskenny.co;

  index index.html;

  server_name jameskenny.io www.jameskenny.io;

  location / {
    try_files $uri $uri/ =404;
  }
}

A sample config of a reverse proxy for a docker container.

server {
  listen 80;

  listen [::]:80;

  server_name touroperator.io www.touroperator.io;

   set $upstream 127.0.0.1:8080;

 location / {
 
 proxy_pass_header Authorization;
 proxy_pass http://$upstream;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_http_version 1.1;
 proxy_set_header Connection "";
 proxy_buffering off;
 client_max_body_size 0;
 proxy_read_timeout 36000s;
 proxy_redirect off;

 }
}

Adding a pointer for sites-enabled. I have created a config for my site in site-available

ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.conf

Tagged in:

NGINX

Last Update: March 01, 2019

About the Author