Difference between revisions of "Nginx"
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
* [http://nginx.org/en/docs/beginners_guide.html Beginner's Guide] | * [http://nginx.org/en/docs/beginners_guide.html Beginner's Guide] | ||
* [http://nginx.org/en/docs/dirindex.html Alphabetical List of Directives] | * [http://nginx.org/en/docs/dirindex.html Alphabetical List of Directives] | ||
+ | * [http://nginx.org/en/docs/varindex.html Alphabetical index of VARIABLES] - start with dollar sign $, like <code>$uri</code>, </code>$document_root</code> etc... | ||
* Master process - read and evaluate configuration, and maintain worker processes | * Master process - read and evaluate configuration, and maintain worker processes | ||
* Worker processes - do actual processing of requests; # is defined in the configuration file | * Worker processes - do actual processing of requests; # is defined in the configuration file | ||
Line 14: | Line 15: | ||
** simple directive - directive name, followed by params, ends with a semicolon | ** simple directive - directive name, followed by params, ends with a semicolon | ||
** block directives ("context") - same as simple, but instead of semicolon ends with curly braces | ** block directives ("context") - same as simple, but instead of semicolon ends with curly braces | ||
+ | ===Common directives=== | ||
+ | * Regular expressions parameter arguments for location directives always start with a tilde ~ and usually are between ^ and $ opperators. | ||
+ | * <code>root path;</code> | ||
+ | ** Sets the root directory for requests. | ||
+ | ** SIMPLE mapping URI to filepath on server. | ||
+ | ** Path to the file is constructed by merely adding a URI to the value of the root directive. | ||
+ | * <code>alias path;</code> | ||
+ | ** Has all the functionality of root directive, plus rewrite capabilities | ||
+ | ** If location URI has a regular expression in it, you can use the <code>$1</code>, <code>$2</code>, etc capture groups in the argument to the alias directive. | ||
+ | * <code>try_files file1, [file2, ...] uri|=code;</code> | ||
+ | ** Checks the existence of files in the specified order and uses the first found file for request processing | ||
+ | ** The path to a file is constructed from the file parameter according to the root and alias directives. | ||
===Contexts=== | ===Contexts=== | ||
====events==== | ====events==== | ||
Line 23: | Line 36: | ||
* Can have multiple server names | * Can have multiple server names | ||
* Once nginx decides which server will process the request, it tests the URI specified in the request's header against the location directives defined in the server block. | * Once nginx decides which server will process the request, it tests the URI specified in the request's header against the location directives defined in the server block. | ||
− | + | * Order of precedence is longest to shortest prefix, so location '/' will match last, THEN regular expressions terminating on the first match | |
+ | * | ||
====location==== | ====location==== | ||
− | * | + | * server context, plus nested inside another location directive is possible, i guess? |
* Performs mapping of URL to route to static files on server, or proxy, etc. | * Performs mapping of URL to route to static files on server, or proxy, etc. | ||
− | * <code>location URIPREFIXARG { root /path/to/static/files;}</code> | + | * The matching is performed against a normalized URI, after decoding the text encoded in the “%XX” form, resolving references to relative path components “.” and “..”, and possible compression of two or more adjacent slashes into a single slash. |
+ | * location can be prefix string or regular expression, e.g., <code>location URIPREFIXARG { root /path/to/static/files;}</code> | ||
+ | * Prefacing URI with = token sets up exact match, with search terminating immediately, speeding up processing. | ||
+ | * Prefacing URI with ~ token means case-sensitive matching | ||
+ | * Prefacing URI with ~* token means case-INsensitive matching | ||
+ | * Prefacing URI with ^~ token means TURN REGULAR EXPRESSION MATCHING OFF for the given prefix. | ||
+ | * The “@” prefix defines a named location. Such a location is not used for a regular request processing, but instead used for request redirection. | ||
+ | |||
==Setup== | ==Setup== | ||
* [https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 LEMP stack on CentOS7] | * [https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 LEMP stack on CentOS7] | ||
+ | |||
+ | ==FastCGI== | ||
+ | ===PHP-fpm=== | ||
+ | * PHP FastCGI Process Manager | ||
+ | |||
+ | ===Perl=== | ||
+ | * [https://www.linode.com/docs/web-servers/nginx/nginx-and-perlfastcgi-on-ubuntu-12-04-lts-precise-pangolin/ Perl-FastCGI on Nginx Ubuntu 12.04] |
Revision as of 19:23, 27 August 2019
Contents
General
- HTTP and reverse proxy server, mail proxy server
- Employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes
- docs
- Beginner's Guide
- Alphabetical List of Directives
- Alphabetical index of VARIABLES - start with dollar sign $, like
$uri
, $document_root etc... - Master process - read and evaluate configuration, and maintain worker processes
- Worker processes - do actual processing of requests; # is defined in the configuration file
Configuration File
- Comments start with hash #
Structure
- nginx modules controlled by directives
- two types of directives: simple and block directives
- simple directive - directive name, followed by params, ends with a semicolon
- block directives ("context") - same as simple, but instead of semicolon ends with curly braces
Common directives
- Regular expressions parameter arguments for location directives always start with a tilde ~ and usually are between ^ and $ opperators.
root path;
- Sets the root directory for requests.
- SIMPLE mapping URI to filepath on server.
- Path to the file is constructed by merely adding a URI to the value of the root directive.
alias path;
- Has all the functionality of root directive, plus rewrite capabilities
- If location URI has a regular expression in it, you can use the
$1
,$2
, etc capture groups in the argument to the alias directive.
try_files file1, [file2, ...] uri|=code;
- Checks the existence of files in the specified order and uses the first found file for request processing
- The path to a file is constructed from the file parameter according to the root and alias directives.
Contexts
events
- top-level "main" context, cannot be within another
http
- top-level "main" context, cannot be within another
server
- Within http context only
- Can have multiple server names
- Once nginx decides which server will process the request, it tests the URI specified in the request's header against the location directives defined in the server block.
- Order of precedence is longest to shortest prefix, so location '/' will match last, THEN regular expressions terminating on the first match
location
- server context, plus nested inside another location directive is possible, i guess?
- Performs mapping of URL to route to static files on server, or proxy, etc.
- The matching is performed against a normalized URI, after decoding the text encoded in the “%XX” form, resolving references to relative path components “.” and “..”, and possible compression of two or more adjacent slashes into a single slash.
- location can be prefix string or regular expression, e.g.,
location URIPREFIXARG { root /path/to/static/files;}
- Prefacing URI with = token sets up exact match, with search terminating immediately, speeding up processing.
- Prefacing URI with ~ token means case-sensitive matching
- Prefacing URI with ~* token means case-INsensitive matching
- Prefacing URI with ^~ token means TURN REGULAR EXPRESSION MATCHING OFF for the given prefix.
- The “@” prefix defines a named location. Such a location is not used for a regular request processing, but instead used for request redirection.
Setup
FastCGI
PHP-fpm
- PHP FastCGI Process Manager