阿里云虚拟主机Web服务器_Nginx location匹配错误
阿里云虚拟主机做Nginx location匹配错误,宝塔面板用户在面板"网站"里改配置,面板自动检测语法。手动改 /www/server/panel/vhost/nginx/ 下的配置后,必须nginx -t通过再reload,否则整站挂。
Nginx常见指令:root(网站根目录)、index(默认首页)、server_name(域名)、listen(端口)、location(URL匹配,=精确 ^~前缀 ~正则)、try_files(文件查找)、rewrite(URL重写)、proxy_pass(反向代理)、fastcgi_pass(PHP处理)、return(返回状态码)、access_log/error_log(日志)。
参考(Nginx配置与排查): ``` # 语法检测与重载 nginx -t nginx -s reload # 或 systemctl reload nginx
# 服务状态 systemctl status nginx systemctl restart nginx
# 错误日志 tail -50 /var/log/nginx/error.log tail -100 /www/wwwlogs/错误日志.log
# 端口监听 netstat -tlnp | grep nginx ss -tlnp | grep :80
# Nginx站点配置示例 server { listen 80; server_name 域名; root /www/wwwroot/域名; index index.html index.php;
# 伪静态 location / { try_files $uri $uri/ /index.php?$query_string; }
# PHP location ~ .php$ { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; }
# 上传大小 client_max_body_size 100m;
# 禁止敏感文件 location ~* .(sql|bak|log|sh)$ { deny all; } } ```
安全配置:server_tokens off隐藏版本号、add_header X-Frame-Options SAMEORIGIN防点击劫持、add_header X-Content-Type-Options nosniff、SSL用TLS1.2+、禁止敏感文件访问(location ~* .(sql|bak|log)$ { deny all; })、后台路径IP白名单、限流limit_req。
Nginx错误日志速查:"emerg" 配置语法错(nginx -t看行号)、"alert" 权限问题、"crit" 资源不足、"error" 一般错误(404/403/502)、"warn" 警告。日志级别在error_log指令设置,生产环境用warn或error,调试用debug。

更新时间:2026-08-27 00:06:43
上一篇:宝塔宝塔面板故障_修复实操