Nginx Basics: Difference between revisions

From WikiMLT
m (Spas moved page NGINX Basic Setup to Nginx Basics without leaving a redirect)
m (Стадий: 6 [Фаза:Утвърждаване, Статус:Утвърден]; Категория:Web Servers)
 
(2 intermediate revisions by the same user not shown)
Line 78: Line 78:
{{devStage  
{{devStage  
  | Прндл  = Web Servers
  | Прндл  = Web Servers
  | Стадий = 3
  | Стадий = 6
  | Фаза  = Разработване
  | Фаза  = Утвърждаване
  | Статус = Разработван
  | Статус = Утвърден
  | ИдтПт  = Spas
  | ИдтПт  = Spas
  | РзбПт  = {{REVISIONUSER}}
  | РзбПт = Spas
| АвтПт  = Spas
| УтвПт = {{REVISIONUSER}}
  | ИдтДт  = 17.09.2022
  | ИдтДт  = 17.09.2022
  | РзбДт  = {{Today}}
  | РзбДт = 18.02.2023
| АвтДт  = 18.02.2023
| УтвДт = {{Today}}
  | ИдтРв  = [[Special:Permalink/31604|31604]]
  | ИдтРв  = [[Special:Permalink/31604|31604]]
  | РзбРв  = {{REVISIONID}}
  | РзбРв = [[Special:Permalink/32258|32258]]
| АвтРв  = [[Special:Permalink/32259|32259]]
| УтвРв = {{REVISIONID}}
}}
}}
</div>
</div>
</noinclude>
</noinclude>

Latest revision as of 11:45, 18 February 2023

Ng­inx CLI

sudo nginx -h
nginx version: nginx/1.18.0 (Ubuntu)
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/share/nginx/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file

Con­trol via sys­tem­ctl.

sudo systemctl start nginx.service
sudo systemctl stop nginx.service
sudo systemctl reload nginx.service
sudo systemctl restart nginx.service

En­able or Dis­able a Vir­tu­al Host Con­fig­u­ra­tion

There is not avail­able a na­tive com­mand equiv­a­lent of a2ensite or a2dissite. So we need to cre­ate or re­move the VH rel­e­vant sym­bol­ic links man­u­al­ly.

sudo ln -s /etc/nginx/sites-{available,enabled}/vhost-name.conf
sudo rm /etc/nginx/sites-enabled/vhost-name.conf

Af­ter that test the con­fig­u­ra­tion and re­load (or restart) the ser­vice.

sudo nginx -tq && sudo nginx -s reload

Ex­am­ple Con­fig­u­ra­tion

Here are few ex­am­ple con­fig­u­ra­tions:

PHP En­able

Ng­inx us­es PHP-FPM, so as ref­er­ence how to set­up PHP-FPM see the ar­ti­cle: Set­up PHP on Ubun­tu.

Let's En­crypt

Cur­rent­ly I'm us­ing Let's En­crypt *wild­card cer­tifi­cate, which is not com­pat­i­ble with the Ng­inx or Apache2 plu­g­ins, how­ev­er to gen­er­ate the helpers con­fig­u­ra­tion file /etc/letsencrypt/options-ssl-nginx.conf you can use the com­mand pro­vid­ed be­low, but first you must test your con­fig­u­ra­tion for er­rors, be­cause it there is some the conf-file will not be cre­at­ed.

sudo nginx -t
sudo certbot --nginx -n  # run non-interactively: -n

Ref­er­ences