我的知识记录

虚拟主机Nginx/Apache配置_修复实操

Nginx/Apache配置的排查流程:配置语法检测 → 服务状态(systemctl status)→ 错误日志(error.log)→ 端口监听(netstat)→ 权限和路径 → 后端服务状态。按流程走,Nginx/Apache问题10分钟内能定位。

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; } } ```

Nginx性能优化:worker_processes auto(和CPU核数一致)、worker_connections 10240、keepalive_timeout 65、gzip on、sendfile on、tcp_nopush on、open_file_cache缓存文件描述符、静态资源expires 30d。优化后并发连接数提升5-10倍,高并发场景必备。

Apache .htaccess不生效:检查httpd.conf里Directory段的AllowOverride是否All(None时 .htaccess完全忽略)、mod_rewrite是否开启(httpd -M | grep rewrite)、.htaccess文件权限644、路径是否在网站根目录。虚拟主机用户在面板开启"伪静态"。

虚拟主机Nginx/Apache配置_修复实操

标签:

更新时间:2026-09-02 15:29:56

上一篇:网站反向代理403 Forbidden修复修复教程

下一篇:虚拟主机批量替换模板文字_避免误改的安全做法