Repository navigation
Expand file tree
/
Copy pathnginx.conf.example
More file actions
92 lines (77 loc) · 2.12 KB
/
Copy pathnginx.conf.example
File metadata and controls
92 lines (77 loc) · 2.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
# LightMemos Nginx 配置示例
# 将此配置添加到你的 Nginx server 块中
server {
listen 80;
server_name your-domain.com;
root /path/to/LightMemos;
index index.php index.html;
# 字符集
charset utf-8;
# 日志
access_log /var/log/nginx/lightmemos-access.log;
error_log /var/log/nginx/lightmemos-error.log;
# 最大上传大小
client_max_body_size 10M;
# 默认首页
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# 保护敏感文件
location ~ ^/(config\.php|\.htaccess|\.git|composer\.(json|lock)) {
deny all;
return 404;
}
# 保护 data 目录(数据库文件)
location ^~ /data/ {
deny all;
return 404;
}
# 保护 backups 目录
location ^~ /backups/ {
deny all;
return 404;
}
# 允许访问 uploads 目录中的文件
location ^~ /uploads/ {
try_files $uri =404;
}
# PHP 文件处理
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 或 127.0.0.1:9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# PHP 设置
fastcgi_param PHP_VALUE "upload_max_filesize=10M \n post_max_size=10M \n max_execution_time=30 \n memory_limit=128M";
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 静态文件缓存
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}
# HTTPS 配置示例(推荐)
# server {
# listen 443 ssl http2;
# server_name your-domain.com;
# root /path/to/LightMemos;
#
# ssl_certificate /path/to/cert.pem;
# ssl_certificate_key /path/to/key.pem;
#
# # ... 复制上面的其他配置 ...
# }
#
# # HTTP 自动跳转 HTTPS
# server {
# listen 80;
# server_name your-domain.com;
# return 301 https://$server_name$request_uri;
# }