下面是一个基本的 Laravel Nginx 配置文件示例:
php
server {
listen 80;
listen [::]:80;
root /path/to/your/public;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
这个配置文件的作用是将所有传入的请求都尝试解析为文件或目录。如果找不到,就会调用 index.php 处理。