Nginx Basics: Difference between revisions
m (Spas moved page NGINX Basic Setup to Nginx Basics without leaving a redirect) |
m (Стадий: 4 [Фаза:Авторизиране, Статус:Разработен]; Категория:Web Servers) |
||
Line 78: | Line 78: | ||
{{devStage | {{devStage | ||
| Прндл = Web Servers | | Прндл = Web Servers | ||
| Стадий = | | Стадий = 4 | ||
| Фаза = | | Фаза = Авторизиране | ||
| Статус = | | Статус = Разработен | ||
| ИдтПт = Spas | | ИдтПт = Spas | ||
| РзбПт = {{REVISIONUSER}} | | РзбПт = Spas | ||
| АвтПт = {{REVISIONUSER}} | |||
| ИдтДт = 17.09.2022 | | ИдтДт = 17.09.2022 | ||
| РзбДт = {{Today}} | | РзбДт = 18.02.2023 | ||
| АвтДт = {{Today}} | |||
| ИдтРв = [[Special:Permalink/31604|31604]] | | ИдтРв = [[Special:Permalink/31604|31604]] | ||
| РзбРв = {{REVISIONID}} | | РзбРв = [[Special:Permalink/32258|32258]] | ||
| АвтРв = {{REVISIONID}} | |||
}} | }} | ||
</div> | </div> | ||
</noinclude> | </noinclude> |
Revision as of 10:45, 18 February 2023
Nginx 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
Control via systemctl
.
sudo systemctl start nginx.service
sudo systemctl stop nginx.service
sudo systemctl reload nginx.service
sudo systemctl restart nginx.service
Enable or Disable a Virtual Host Configuration
There is not available a native command equivalent of a2ensite
or a2dissite
. So we need to create or remove the VH relevant symbolic links manually.
sudo ln -s /etc/nginx/sites-{available,enabled}/vhost-name.conf
sudo rm /etc/nginx/sites-enabled/vhost-name.conf
After that test the configuration and reload (or restart) the service.
sudo nginx -tq && sudo nginx -s reload
Example Configuration
Here are few example configurations:
- Laravel compatible setup – where Laravel is served on the base URL. This example is based on Laravel 10.x Docs.
- Laravel+React compatible setup – where React is served on the base URL and Laravel is served on the sub path (location)
/laravel
. Note: in a real world Laravel+React application we do not need such complicated setup, but the scenario of the concrete exercise requires it. This example uses a solution provided within the answers of this Stack Overflow topic: Config nginx for Laravel In a subfolder. - Find more examples within the references below.
PHP Enable
Nginx uses PHP-FPM, so as reference how to setup PHP-FPM see the article: Setup PHP on Ubuntu.
Let's Encrypt
Currently I'm using Let's Encrypt *wildcard certificate, which is not compatible with the Nginx or Apache2 plugins, however to generate the helpers configuration file /etc/letsencrypt/options-ssl-nginx.conf
you can use the command provided below, but first you must test your configuration for errors, because it there is some the conf-file will not be created.
sudo nginx -t
sudo certbot --nginx -n # run non-interactively: -n
References
- NGINX Docs: Product Documentation
- NGINX Docs: NGINX ModSecurity WAF Documentation
- Linode Docs: Securing Nginx With ModSecurity
- NGINX Part of F5: F5 NGINX ModSecurity WAF Is Transitioning to End-of-Life
- TrustWave Software Updates: End of Sale and Trustwave Support for ModSecurity Web Application Firewall
- OWASP Docs: OWASP Core Ruleset Project announces Coraza SecLang engine
- Proxmox VE Wiki: Web Interface Via Nginx Proxy
- Server Fault: How to set up Nginx as a caching reverse proxy?
- Server Fault: Nginx enable site command