Nginx配置php-fpm程序示例

配置示例

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
server {
listen 80;
server_name domain.com;

access_log off;
error_log /dev/null crit;

return 308 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name domain.com;

index index.php;
root /wwwroot/project_path;

access_log /log_path/xxx.log;
error_log /log_path/xxx_error.log;

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;

location / {
# Laravel
try_files $uri $uri/ /index.php?$query_string;

# Yii
try_files $uri $uri/ /index.php$is_args$args;

# ThinkPHP
try_files $uri $uri/ /index.php$uri?$query_string;
}

location ~ \.php$ {
# fastcgi_pass unix:/run/php/php8.0-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

# Laravel/Yii
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

# ThinkPHP
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

评论