-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathnginx-root.conf
More file actions
97 lines (86 loc) · 2.62 KB
/
nginx-root.conf
File metadata and controls
97 lines (86 loc) · 2.62 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Nginx配置文件 - 根目录部署
# 适用于将DrPlayer部署在域名根目录的情况
# 例如: https://example.com/
server {
listen 80;
server_name localhost; # 请替换为您的域名
# 网站根目录,指向Vue构建后的dist目录
root /var/www/html/drplayer; # 请替换为您的实际路径
index index.html;
# 启用gzip压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# 静态资源缓存配置
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# API代理配置(如果需要)
# location /api/ {
# proxy_pass http://backend-server;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
# Vue Router History模式支持
# 所有不匹配静态文件的请求都返回index.html
location / {
try_files $uri $uri/ /index.html;
# 安全头设置
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 禁止访问备份文件
location ~ ~$ {
deny all;
access_log off;
log_not_found off;
}
# 错误页面
error_page 404 /index.html;
error_page 500 502 503 504 /index.html;
}
# HTTPS配置示例(可选)
# server {
# listen 443 ssl http2;
# server_name localhost; # 请替换为您的域名
#
# ssl_certificate /path/to/your/certificate.crt;
# ssl_certificate_key /path/to/your/private.key;
#
# # SSL配置
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
# ssl_prefer_server_ciphers off;
#
# # 其他配置与HTTP相同
# root /var/www/html/drplayer;
# index index.html;
#
# location / {
# try_files $uri $uri/ /index.html;
# }
# }