-
Notifications
You must be signed in to change notification settings - Fork 3
/
nginx.conf
76 lines (62 loc) · 2.77 KB
/
nginx.conf
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
server {
listen 80;
server_name www.example.com;
server_tokens off;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443;
server_name www.example.com;
server_tokens off;
## 无ssl 请把ssl部分全部注释
ssl_certificate /etc/nginx/ssl/example.com.cer;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
# Recommendations from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers '!aNULL:kECDH+AESGCM:ECDH+AESGCM:RSA+AESGCM:kECDH+AES:ECDH+AES:RSA+AES:';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
# disable any limits to avoid HTTP 413 for large image uploads
client_max_body_size 0;
location / {
root /data/www/example.com/www;
index index.php index.html index.htm;
}
location ~ .php$ {
root /data/www/example.com/www;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
## /var/www/html 是docker 容器里面的目录
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
##匹配nginx需要交给php-fpm执行的URI,先要允许pathinfo格式的URL能够被匹配到
##所以要去掉$
##nginx文档中的匹配规则为:^(.+\.php)(.*)$
##还有~ \.php这种写法 和 ~ \.php($|/)这种写法
##都是差不多意思没啥严格区别
##唯一区别就是有多个匹配php的location的话需要留意权重差异
location ~ ^(.+\.php)(.*)$ {
root /data/www/example.com/www;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
##增加 fastcgi_split_path_info指令,将URI匹配成PHP脚本的URI和pathinfo两个变量
##即$fastcgi_script_name 和$fastcgi_path_info
fastcgi_split_path_info ^(.+\.php)(.*)$;
##PHP中要能读取到pathinfo这个变量
##就要通过fastcgi_param指令将fastcgi_split_path_info指令匹配到的pathinfo部分赋值给PATH_INFO
##这样PHP中$_SERVER['PATH_INFO']才会存在值
fastcgi_param PATH_INFO $fastcgi_path_info;
##在将这个请求的URI匹配完毕后,检查这个绝对地址的PHP脚本文件是否存在
##如果这个PHP脚本文件不存在就不用交给php-fpm来执行了
##否者页面将出现由php-fpm返回的:`File not found.`的提示
## 代码在Docker里面,无需判断!!!
##if (!-e /var/www/html/$fastcgi_script_name) {
##此处直接返回404错误
##你也可以rewrite 到新地址去,然后break;
# return 404;
#}
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}