Nginx配置静态网站示例

配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
server {
listen 80;
server_name domain.com;

access_log off;
error_log /dev/null crit;

rewrite ^(.*) https://$host$1 permanent;
}

server {
listen 443 ssl;
server_name domain.com;

index index.html;
root /wwwroot/project_path;

ssl_certificate /ssl_cert_path/cert.pem;
ssl_certificate_key /ssl_cert_path/key.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;

access_log off;
error_log /dev/null crit;

location / {
# 纯静态
try_files $uri $uri/ =404;
# 将首页指向index.html
try_files $uri $uri/ /index.html;
}

location ~ .*\.(js|css|json|txt)?$ {
expires 7d;
}

location ~ .*\.(eot|ttf|otf|woff|svg)$ {
expires 30d;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
}

error_page 404 /404.html;
location = /404.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

gzip on;
gzip_min_length 1k;
gzip_static on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml text/javascript application/javascript application/x-javascript text/x-json application/json application/x-web-app-manifest+json text/css text/plain text/x-component font/opentype font/ttf application/x-font-ttf application/vnd.ms-fontobject image/x-icon image/png image/jpeg image/gif image/bmp image/ief;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
}

评论