-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
159 lines (138 loc) · 3.75 KB
/
Copy pathnginx.conf
File metadata and controls
159 lines (138 loc) · 3.75 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Yikai CMS Nginx Configuration
# 将以下配置添加到你的 server 块中
# 禁止访问隐藏文件
location ~ /\. {
deny all;
}
# 禁止访问config目录
location ^~ /config/ {
deny all;
}
# 禁止访问storage目录(SQLite数据库)
location ^~ /storage/ {
deny all;
}
# 安装完成后禁止访问install目录
location ^~ /install/ {
if (-f $document_root/installed.lock) {
return 403;
}
}
# 伪静态规则
# 栏目列表页 (ID格式)
location ~ ^/list/(\d+)\.html$ {
rewrite ^/list/(\d+)\.html$ /list.php?id=$1 last;
}
location ~ ^/list/(\d+)/page/(\d+)\.html$ {
rewrite ^/list/(\d+)/page/(\d+)\.html$ /list.php?id=$1&page=$2 last;
}
# 栏目列表页 (slug格式带分页)
location ~ ^/([a-z0-9_-]+)/page/(\d+)\.html$ {
rewrite ^/([a-z0-9_-]+)/page/(\d+)\.html$ /list.php?slug=$1&page=$2 last;
}
# 列表页 (ID格式带分页)
location ~ ^/list/(\d+)/page/(\d+)\.html$ {
rewrite ^/list/(\d+)/page/(\d+)\.html$ /list.php?id=$1&page=$2 last;
}
# 详情页 (ID格式)
location ~ ^/detail/(\d+)\.html$ {
rewrite ^/detail/(\d+)\.html$ /detail.php?id=$1 last;
}
# 产品分类页
location ~ ^/product/([a-z0-9_-]+)/page/(\d+)\.html$ {
rewrite ^/product/([a-z0-9_-]+)/page/(\d+)\.html$ /list.php?slug=product&cat=$1&page=$2 last;
}
location ~ ^/product/([a-z0-9_-]+)\.html$ {
rewrite ^/product/([a-z0-9_-]+)\.html$ /list.php?slug=product&cat=$1 last;
}
# 产品详情页 (ID格式)
location ~ ^/product/(\d+)\.html$ {
rewrite ^/product/(\d+)\.html$ /product.php?id=$1 last;
}
# 单页 (ID格式)
location ~ ^/page/(\d+)\.html$ {
rewrite ^/page/(\d+)\.html$ /page.php?id=$1 last;
}
# 二级单页 (slug格式: /parent/child.html)
location ~ ^/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$ {
rewrite ^/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$ /page.php?parent=$1&slug=$2 last;
}
# 一级页面 (slug格式: /slug.html)
location ~ ^/([a-z0-9_-]+)\.html$ {
rewrite ^/([a-z0-9_-]+)\.html$ /page.php?slug=$1 last;
}
# 联系页面
location = /contact.html {
rewrite ^ /contact.php last;
}
# PHP 处理
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 静态文件缓存
location ~* \.(jpg|jpeg|png|gif|ico|css|js|webp|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
# 默认处理
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# ============================================
# 完整示例配置(phpStudy 面板格式)
# ============================================
#
# server {
# listen 80;
# server_name www.example.com example.com;
# root /path/to/ikaicms;
# index index.php index.html;
#
# # 禁止访问隐藏文件
# location ~ /\. {
# deny all;
# }
#
# # 禁止访问敏感目录
# location ^~ /config/ {
# deny all;
# }
#
# location ^~ /storage/ {
# deny all;
# }
#
# # 伪静态
# location ~ ^/list/(\d+)\.html$ {
# rewrite ^/list/(\d+)\.html$ /list.php?id=$1 last;
# }
#
# location ~ ^/detail/(\d+)\.html$ {
# rewrite ^/detail/(\d+)\.html$ /detail.php?id=$1 last;
# }
#
# location ~ ^/page/(\d+)\.html$ {
# rewrite ^/page/(\d+)\.html$ /page.php?id=$1 last;
# }
#
# # PHP处理
# location ~ \.php$ {
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
# }
#
# # 静态文件
# location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
# expires 30d;
# }
#
# # 默认
# location / {
# try_files $uri $uri/ /index.php?$query_string;
# }
# }