-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathnginx-subdir.conf
More file actions
115 lines (101 loc) · 3.12 KB
/
nginx-subdir.conf
File metadata and controls
115 lines (101 loc) · 3.12 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Nginx配置文件 - 子目录部署
# 适用于将DrPlayer部署在域名子目录的情况
# 例如: https://example.com/apps/drplayer/
server {
listen 80;
server_name localhost; # 请替换为您的域名
# 网站根目录
root /var/www/html;
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;
# DrPlayer应用配置 - 子目录部署
location /apps/drplayer/ {
alias /var/www/html/drplayer/; # 请替换为您的实际路径
# 静态资源缓存配置
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# Vue Router History模式支持
# 所有不匹配静态文件的请求都返回index.html
try_files $uri $uri/ /apps/drplayer/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;
}
# 处理DrPlayer的根路径访问
location = /apps/drplayer {
return 301 /apps/drplayer/;
}
# API代理配置(如果需要)
# location /apps/drplayer/api/ {
# proxy_pass http://backend-server/api/;
# 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;
# }
# 其他应用或默认站点配置
location / {
try_files $uri $uri/ =404;
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 禁止访问备份文件
location ~ ~$ {
deny all;
access_log off;
log_not_found off;
}
# 错误页面
error_page 404 /404.html;
error_page 500 502 503 504 /50x.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;
# index index.html;
#
# location /apps/drplayer/ {
# alias /var/www/html/drplayer/;
# try_files $uri $uri/ /apps/drplayer/index.html;
# }
#
# location = /apps/drplayer {
# return 301 /apps/drplayer/;
# }
# }