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.
|
to create a simple proxy server, etc.
|
||||||
|
|
||||||
This article provides simple examples of Nginx configs for different purposes.
|
This article provides simple examples of Nginx configs for different purposes.
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
|
|
||||||
For the following configs to work, you need to put them in the path `/etc/nginx/conf.d/<some_name>.conf`, then check
|
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:
|
config validity:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
nginx -t
|
nginx -t
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run the command to apply the config:
|
Then run the command to apply the config:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example 1: hosting a static site.
|
## Example 1: hosting a static site.
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
@ -32,7 +39,9 @@ server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example 2: proxy server
|
## Example 2: proxy server
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
@ -49,15 +58,20 @@ server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example 3: caching proxy
|
## Example 3: caching proxy
|
||||||
|
|
||||||
In `/etc/nginx/nginx.conf` add:
|
In `/etc/nginx/nginx.conf` add:
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
http {
|
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;
|
inactive=24h max_size=1g;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
In `/etc/nginx/conf.d` put the following config:
|
In `/etc/nginx/conf.d` put the following config:
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
@ -69,8 +83,7 @@ server {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_cache STATIC;
|
proxy_cache STATIC;
|
||||||
proxy_cache_valid 200 1d;
|
proxy_cache_valid 200 1d;
|
||||||
proxy_cache_use_stale error timeout invalid_header updating
|
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
|
||||||
http_500 http_502 http_503 http_504;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
|
@ -65,7 +65,7 @@ server {
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
http {
|
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;
|
inactive=24h max_size=1g;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -83,8 +83,7 @@ server {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_cache STATIC;
|
proxy_cache STATIC;
|
||||||
proxy_cache_valid 200 1d;
|
proxy_cache_valid 200 1d;
|
||||||
proxy_cache_use_stale error timeout invalid_header updating
|
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
|
||||||
http_500 http_502 http_503 http_504;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
Loading…
Reference in New Issue