Nginx 配置笔记

引子

本篇记录学习 nginx 的点滴

主要配置

整合 ThinkPHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vim nginx.conf

location / {
root /var/www/html;
index index.html index.php;
# ThinkPHP hide index.php
try_files $uri $uri/ /index.php?s=$uri&$args;
}

location ~ \.php {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi.conf;
}

设置 HTTPS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate server.crt; # 注意 bundle.crt
ssl_certificate_key server.key;

# 强制 HTTPS

server {
listen 80;
rewrite ^(.*)$ https://$host$1 permanent;
}

server {
listen 443;
# blahblah....
}

参考资料

https://s.how/nginx-ssl/