|
@@ -0,0 +1,34 @@
|
|
1
|
+:source-highlighter: pygments
|
|
2
|
+:source-language: nginx
|
|
3
|
+
|
|
4
|
+== Nginx
|
|
5
|
+
|
|
6
|
+=== Redirecting image requests to webp versions
|
|
7
|
+
|
|
8
|
+[source]
|
|
9
|
+----
|
|
10
|
+http {
|
|
11
|
+ map $http_accept $webp_suffix {
|
|
12
|
+ "~*webp" ".webp";
|
|
13
|
+ }
|
|
14
|
+
|
|
15
|
+ server {
|
|
16
|
+ location ~ \.(png|jpe?g)$ {
|
|
17
|
+ try_files $uri$webp_suffix $uri =404;
|
|
18
|
+ expires 1y;
|
|
19
|
+ }
|
|
20
|
+ }
|
|
21
|
+}
|
|
22
|
+----
|
|
23
|
+
|
|
24
|
+=== Redirecting to a canonical domain
|
|
25
|
+
|
|
26
|
+Instead of complex rules to redirect certain requests, just add a separate `server` block:
|
|
27
|
+
|
|
28
|
+[source]
|
|
29
|
+----
|
|
30
|
+server {
|
|
31
|
+ server_name www.example.com;
|
|
32
|
+ return 301 $scheme://example.com$request_uri;
|
|
33
|
+}
|
|
34
|
+----
|