我有一个Laravel项目。它可以在Mac OS和Nginx上运行。我最近安装了CentOs8。在其上安装了Nginx并添加了以下配置:
server {
listen 8001;
server_name _;
root /usr/share/nginx/html/reservation_laravel/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm 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;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
web.php内的所有路由都可以,但是API路由不起作用!相同的配置正在Ubuntu服务器上工作!
当您在api.php上编写时,在您的网址上添加api,例如
'/get-list'
然后您称呼它
/api/get-list
我不确定您是否有重写问题。看一下Laravel的安装文档。有一节关于重写配置,可能会给您一些启示: