在 Ubuntu 中配置 ThinkPHP 路由,你需要遵循以下步骤:
composer create-project topthink/think=latest-version your_project_name
将 your_project_name 替换为你的项目名称。
/etc/nginx/sites-available/your_project_name。将 your_project_name 替换为你的项目名称。在新配置文件中,添加以下内容:server {
listen 80;
server_name your_domain_or_ip;
root /path/to/your_project_name/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
将 your_domain_or_ip 替换为你的域名或 IP 地址,将 /path/to/your_project_name 替换为你的项目实际路径。
/etc/nginx/sites-enabled 目录:sudo ln -s /etc/nginx/sites-available/your_project_name /etc/nginx/sites-enabled/
sudo service nginx restart
application/route.php 文件。在这个文件中,你可以定义你的路由规则。例如:<?php
// 应用入口文件
use think\facade\Route;
Route::get('/', 'index/Index/index'); // 首页
Route::get('/about', 'index/Index/about'); // 关于页面
Route::post('/submit', 'index/Index/submit'); // 提交表单
现在,你的 ThinkPHP 项目已经配置好了路由。访问你在 Nginx 配置中设置的域名或 IP 地址,你应该能看到相应的页面。