在 Laravel 中,路由配置是通过在 routes
目录下的文件中定义的。对于 CentOS 系统,你可能需要先确保已经正确安装了 PHP、Apache 或 Nginx 以及 Laravel。以下是在 CentOS 上配置 Laravel 路由的一些建议:
composer create-project --prefer-dist laravel/laravel your_project_name
httpd.conf
文件中添加以下内容:<VirtualHost *:80>
ServerName your_domain.com
DocumentRoot /path/to/your/laravel_project/public
<Directory /path/to/your/laravel_project/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
nginx.conf
文件中添加以下内容:server {
listen 80;
server_name your_domain.com;
root /path/to/your/laravel_project/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;
}
}
routes/web.php
文件中定义你的路由。例如:Route::get('/', function () {
return 'Hello, World!';
});
Route::get('/about', function () {
return 'About page';
});
sudo systemctl restart httpd
sudo systemctl restart nginx
现在,你应该可以通过访问 http://your_domain.com
和 http://your_domain.com/about
来查看你的 Laravel 应用程序了。如果你遇到任何问题,请检查 Web 服务器和 Laravel 的日志文件以获取更多信息。