首次搭建Nginx部署Laravel应用 执行nginx -t报log_not_found参数错误如何解决
问题根源
你的Nginx配置存在两处语法错误,均为编辑/复制过程中意外换行拆分参数导致:
- 配置第18、19行的
log_not_found off被错误拆分为两行,变成不完整的log_not_found of和单独的f;,Nginx无法识别拆分后的非法指令 - 配置第28行的
$fastcgi_script_name变量被错误拆分为两行,变成$fastcgi_s和单独的cript_name;,导致参数不完整
修正后的完整配置
server { listen 80; server_name 142.93.111.117; root /var/www/colosseo60/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 { return 204; access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } }
验证步骤
替换配置文件后重新执行配置测试命令:
sudo nginx -t
如果输出nginx: configuration file /etc/nginx/nginx.conf test is successful即代表配置正常,执行sudo systemctl reload nginx加载新配置即可生效。
内容的提问来源于stack exchange,提问作者gianmarco varrone
相关产品推荐
相关产品推荐

