From a14389916253bcf9e22758d4b5f79057eb3f1ddc Mon Sep 17 00:00:00 2001 From: Digital Studium Date: Sun, 23 Apr 2023 18:33:17 +0300 Subject: [PATCH] Fix nginx config --- .../nginx-lifehacks/nginx-configs-examples.md | 19 ++++++++++++++++--- .../nginx-lifehacks/nginx-configs-examples.md | 5 ++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/content/en/nginx-lifehacks/nginx-configs-examples.md b/content/en/nginx-lifehacks/nginx-configs-examples.md index 11f68af..9955d3d 100644 --- a/content/en/nginx-lifehacks/nginx-configs-examples.md +++ b/content/en/nginx-lifehacks/nginx-configs-examples.md @@ -8,17 +8,24 @@ Sometimes there is a need to quickly create an nginx configuration file: for hos to create a simple proxy server, etc. This article provides simple examples of Nginx configs for different purposes. + + For the following configs to work, you need to put them in the path `/etc/nginx/conf.d/.conf`, then check config validity: + ```bash nginx -t ``` + Then run the command to apply the config: + ```bash sudo service nginx reload ``` + ## Example 1: hosting a static site. + ```nginx server { listen 80; @@ -32,7 +39,9 @@ server { } } ``` + ## Example 2: proxy server + ```nginx server { listen 80; @@ -49,15 +58,20 @@ server { } } ``` + ## Example 3: caching proxy + In `/etc/nginx/nginx.conf` add: + ```nginx http { - proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m + proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m; inactive=24h max_size=1g; } ``` + In `/etc/nginx/conf.d` put the following config: + ```nginx server { listen 80; @@ -69,8 +83,7 @@ server { proxy_set_header Host $host; proxy_cache STATIC; proxy_cache_valid 200 1d; - proxy_cache_use_stale error timeout invalid_header updating - http_500 http_502 http_503 http_504; + proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; } } ``` \ No newline at end of file diff --git a/content/ru/nginx-lifehacks/nginx-configs-examples.md b/content/ru/nginx-lifehacks/nginx-configs-examples.md index b0a1563..e98e236 100644 --- a/content/ru/nginx-lifehacks/nginx-configs-examples.md +++ b/content/ru/nginx-lifehacks/nginx-configs-examples.md @@ -65,7 +65,7 @@ server { ```nginx http { - proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m + proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m; inactive=24h max_size=1g; } ``` @@ -83,8 +83,7 @@ server { proxy_set_header Host $host; proxy_cache STATIC; proxy_cache_valid 200 1d; - proxy_cache_use_stale error timeout invalid_header updating - http_500 http_502 http_503 http_504; + proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; } } ``` \ No newline at end of file