Fix nginx config
deploy
Details
deploy
Details
This commit is contained in:
parent
dc52bd51e1
commit
a143899162
|
@ -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.
|
||||
|
||||
<!--more-->
|
||||
|
||||
For the following configs to work, you need to put them in the path `/etc/nginx/conf.d/<some_name>.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;
|
||||
}
|
||||
}
|
||||
```
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue