nginxarchitecture
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
nginxarchitecture [2017/03/24 05:58] – [PHP-FPM Config and Optimize] admin | nginxarchitecture [2024/10/27 02:55] (current) – [Basic Nginx Configuration] admin | ||
---|---|---|---|
Line 26: | Line 26: | ||
* Since Nginx comes only with core features that are required for a web server, **it is lightweight when compared to Apache**. | * Since Nginx comes only with core features that are required for a web server, **it is lightweight when compared to Apache**. | ||
* The performance and scalability of Nginx is not completely dependent on hardware resources, whereas the performance and scalability of the Apache is dependent on underlying hardware resources like memory and CPU. | * The performance and scalability of Nginx is not completely dependent on hardware resources, whereas the performance and scalability of the Apache is dependent on underlying hardware resources like memory and CPU. | ||
+ | ===== Basic Nginx Configuration ===== | ||
+ | Some basic directives: | ||
+ | * Location (refer: https:// | ||
+ | user nobody; # a directive in the ' | ||
+ | |||
+ | events { | ||
+ | # configuration of connection processing | ||
+ | } | ||
+ | |||
+ | http { | ||
+ | # Configuration specific to HTTP and affecting all virtual servers | ||
+ | |||
+ | server { | ||
+ | # configuration of HTTP virtual server 1 | ||
+ | location /one { | ||
+ | # configuration for processing URIs starting with '/ | ||
+ | } | ||
+ | location /two { | ||
+ | # configuration for processing URIs starting with '/ | ||
+ | } | ||
+ | } | ||
+ | |||
+ | server { | ||
+ | # configuration of HTTP virtual server 2 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | stream { | ||
+ | # Configuration specific to TCP/UDP and affecting all virtual servers | ||
+ | server { | ||
+ | # configuration of TCP virtual server 1 | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | * request_filename (refer: https:// | ||
+ | if (!-e $request_filename) { rewrite ^ / | ||
+ | </ | ||
+ | * try_files (refer https:// | ||
+ | location / { | ||
+ | try_files $uri $uri/ $uri.html =404; | ||
+ | } | ||
+ | </ | ||
+ | location / { | ||
+ | try_files $uri $uri/ / | ||
+ | } | ||
+ | </ | ||
+ | location / => matches all locations** | ||
+ | try_files $uri =>try $uri first, for example http:// | ||
+ | $uri/=> which means if you didn't find the first condition $uri try the URI as a directory | ||
+ | </ | ||
===== Optimize nginx configuration for performance and benchmark ===== | ===== Optimize nginx configuration for performance and benchmark ===== | ||
refer: | refer: | ||
+ | * http:// | ||
* http:// | * http:// | ||
* http:// | * http:// | ||
Line 138: | Line 189: | ||
* benchmark load speed from other countries from http:// | * benchmark load speed from other countries from http:// | ||
=> with above benchmarch for static file ab -n 20 -c 4 http:// | => with above benchmarch for static file ab -n 20 -c 4 http:// | ||
+ | |||
+ | ===== Nginx Rewrite Rules and Regular Expression ===== | ||
+ | refer: https:// | ||
+ | < | ||
+ | # ----------------------------------------------------------------------------------------- | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # (no char/text after the match) $ is usually used at the end of a regex | ||
+ | # | ||
+ | # ? | ||
+ | # | ||
+ | # any further regular expression match even if an other match is available | ||
+ | # | ||
+ | # the uri text, while ~ indicates a regular expression match mode. | ||
+ | # | ||
+ | # Nginx evaluation exactly this as don't check regexp locations if this | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # {2,4} match length of 2, 3 and 4 | ||
+ | # | ||
+ | # | ||
+ | # -------------------------------------------------------------------------------------------- | ||
+ | </ | ||
===== PHP-FPM Config and Optimize ===== | ===== PHP-FPM Config and Optimize ===== | ||
refer: | refer: | ||
* https:// | * https:// | ||
- | * http://jeremymarc.github.io/2013/04/22/nginx-and-php-fpm-for-performance/ | + | * https://tweaked.io/guide/nginx/ |
**global** config for all pools:< | **global** config for all pools:< | ||
Line 203: | Line 288: | ||
/ | / | ||
/ | / | ||
- | </ | + | </ |
+ | Or config in php-fpm.conf< | ||
+ | ; Relative path can also be used. They will be prefixed by: | ||
+ | ; - the global prefix if it's been set (-p argument) | ||
+ | ; - /onec/php otherwise | ||
+ | ; | ||
+ | </ | ||
Just example configurations for every pool: | Just example configurations for every pool: | ||
+ | * default pool [www](listen on port 9000)< | ||
+ | [www] | ||
+ | |||
+ | ; Per pool prefix | ||
+ | ; It only applies on the following directives: | ||
+ | ; - ' | ||
+ | ; - ' | ||
+ | ; - ' | ||
+ | ; - ' | ||
+ | ; - ' | ||
+ | ; - ' | ||
+ | ; - ' | ||
+ | ; When not set, the global prefix (or /onec/php) applies instead. | ||
+ | ; Note: This directive can also be relative to the global prefix. | ||
+ | ; Default Value: none | ||
+ | ;prefix = / | ||
+ | |||
+ | ; Unix user/group of processes | ||
+ | ; Note: The user is mandatory. If the group is not set, the default user's group | ||
+ | ; will be used. | ||
+ | user = nobody | ||
+ | group = nobody | ||
+ | |||
+ | ; The address on which to accept FastCGI requests. | ||
+ | ; Valid syntaxes are: | ||
+ | ; ' | ||
+ | ; a specific port; | ||
+ | ; ' | ||
+ | ; a specific port; | ||
+ | ; ' | ||
+ | ; specific port; | ||
+ | ; ' | ||
+ | ; (IPv6 and IPv4-mapped) on a specific port; | ||
+ | ; '/ | ||
+ | ; Note: This value is mandatory. | ||
+ | listen = 127.0.0.1: | ||
+ | |||
+ | </ | ||
* / | * / | ||
[site] | [site] |
nginxarchitecture.1490335089.txt.gz · Last modified: 2022/10/29 16:15 (external edit)