# Nginx 配置示例代码,用于 ThinkPHP 伪静态
server {
listen 80;
server_name yourdomain.com; # 替换为你的域名
root /path/to/your/project; # 替换为你的项目路径
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
server块:定义了一个虚拟主机配置。
listen 80; 表示监听80端口。server_name yourdomain.com; 设置服务器的域名,需要替换为你自己的域名。root指令:设置网站根目录,需要替换为你的项目路径。
location /:处理所有请求,尝试匹配文件或目录,如果找不到则转发给 index.php 处理。
try_files $uri $uri/ /index.php?$query_string; 这行代码是关键,它实现了伪静态功能。当访问一个不存在的文件或目录时,会将请求转发给 index.php 并附带原始查询字符串。location ~ .php$:处理 PHP 文件的请求,通过 FastCGI 转发给 PHP-FPM 处理。
fastcgi_pass 127.0.0.1:9000; 指定 PHP-FPM 的地址和端口。fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 设置脚本文件路径。include fastcgi_params; 包含 FastCGI 参数配置文件。location ~ /.ht:禁止访问 .htaccess 文件,确保安全性。
上一篇:php static
下一篇:php跳转页面代码
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站