>_ IzzyLab

Hands-on task

This task is step 5 of the course “nginx basics”

nginx on a Non-Standard Port

medium~10 min

Configure nginx to listen on port 8888 (instead of 80) and serve a page with the text PORT_8888. The page is already prepared at /var/www/p8888/index.html. Port 80 must be left free.

What you'll practise:
  • nginx
  • listen directive
  • server block
  • virtual hosts

Topic breakdown

In nginx the port on which a site accepts requests is set by the listen directive inside a server block, and the static-files directory by the root directive; site configs live in /etc/nginx/sites-available/ with a symlink in sites-enabled/. Here two conditions matter at once: move the site to a non-standard port and make sure no server block listens on 80 anymore (an extra site on 80 is already a mistake). After edits the config is first checked for syntax (nginx -t), then reloaded.

What's checked

  1. port 8888 serves PORT_8888
  2. port 80 is free

What it looks like