在CentOS系統中配置Laravel路由,你需要遵循以下步驟:
composer global require laravel/installer
laravel new project-name
/etc/nginx/conf.d/
目錄下),添加以下內容:server {
listen 80;
server_name example.com; # 替換為你的域名或公網IP
root /path/to/your/laravel/project/public; # 替換為你的Laravel項目的public目錄路徑
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
sudo systemctl restart nginx
routes/web.php
文件,編寫你的路由規則。例如:Route::get('/', function () {
return 'Hello, World!';
});
Route::get('/about', function () {
return 'About page';
});
http://example.com
和http://example.com/about
來測試你的路由是否正常工作。以上就是在CentOS系統中配置Laravel路由的基本步驟。你可以根據自己的需求進一步自定義路由和中間件等設置。