======nginx使用笔记======
* 上传大小限制:
http{
client_max_body_size 1024m;
}
若上传文件的大小超过这个值,会报错:client intended to send too large body
--- //[[wu_xiaokang@163.com|Wu Xiaokiang]] 2021/02/03 10:43//
* 虚拟目录PHP配置
server {
listen 80;
root /srv/www/www.example.com;
index index.php index.html index.htm;
server_name www.example.com;
location / {
try_files $uri $uri/ =404;
}
# 定义虚拟目录,最下层路径名不相同的话只能用alias,不能用root。 实际路径为alias指定路径。用root时,实际路径
# 为root + location。
location /postfixadmin/ {
alias /usr/share/postfixadmin/public/;
index index.html index.php;
}
#这一段必须放到location ~ \.php$之前,否则不生效。
location ~^/postfixadmin/.+\.php$ {
if ($fastcgi_script_name ~ /postfixadmin/(.+\.php.*)$) {
set $valid_fastcgi_script_name $1;
}
fastcgi_param SCRIPT_FILENAME /usr/share/postfixadmin/public/$valid_fastcgi_script_name;
# 若用默认的fastcgi.conf SCRIPT_FILENAME会变成$document_root$fastcgi_script_name,
# 会去/srv/www/www.example.com/postfixadmin/下寻找PHP文件,结果会是404。
# 虚拟目录配PHP支持,关键就是这个变量。
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
try_files $fastcgi_script_name =404;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
access_log /srv/logs/example.log;
error_log /srv/logs/example.error.log;
}