Nginx+PHP环境搭建笔记

nginx安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 下载
wget http://nginx.org/download/nginx-1.16.1.tar.gz

// 解压
tar -xf nginx-1.16.1.tar.gz
cd nginx-1.16.1

// (Ubuntu 18.04.4 LTS)依赖环境
- sudo apt-get install libpcre3-dev
- sudo apt-get install zlib1g-dev
- sudo apt-get install libssl-dev

// 安装
./configure --with-http_ssl_module
// -- 此命令完成后会出现如下输出
// Configuration summary
// + using system PCRE library
// + using system OpenSSL library
// + using system zlib library

make
sudo make install

环境配置

源码安装的nginx是无法直接用service或者systemctl来控制服务的(如有必要,可自己书写控制脚本)

关于启动nginx时遇到的403问题:

  1. 设置location模块的root路径中,所有目录必须至少是 755 权限
  2. 所有的静态资源必须至少是 644 权限

nginx访问php-fpm的sock文件,无权限问题

1
2
# err_log
... fpm.sock failed (13: Permission denied) ...

相关问题:

  • 访问用户权限
  • 文件可访问权限

$fastcgi_script_name 的含义问题

1
2
# err_log
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream ...

相关问题:

  • nginx的location模块中,rootalias关键字的区别
  • fastcgi_passfastcgi_param 项的值

关于一个nginx重定向实例

  • Before:https://klusfq.cn/api/module/xxx?yyy

  • After:https://klusfq.cn/module/index.php/xxx?yyy

1
2
3
4
5
6
rewrite ^/api/([^/.]*)(/[^\?]*)?((\?.*)?)$ /$1/index.php$2$3 break;

# 解析:
# ([^/.]*) -> module -> $1
# (/[^\?]*)? -> /xxx -> $2
# ((\?.*)?) -> ?yyy -> $3
  • Copyrights © 2019-2024 Klusfq
  • Visitors: | Views: