我的知识记录

华夏名网虚拟主机Web服务器_Apache .htaccess不生效

Apache .htaccess不生效时分清是Web服务器本身问题还是后端问题。Nginx 502是后端(PHP-FPM/应用)没响应,504是后端超时,403是Nginx权限或deny规则,404是root路径或伪静态。错误码已经告诉你方向。

Nginx常见指令:root(网站根目录)、index(默认首页)、server_name(域名)、listen(端口)、location(URL匹配,=精确 ^~前缀 ~正则)、try_files(文件查找)、rewrite(URL重写)、proxy_pass(反向代理)、fastcgi_pass(PHP处理)、return(返回状态码)、access_log/error_log(日志)。

参考(Apache配置与排查): ``` # 语法检测 apachectl configtest httpd -t

# 重载与重启 systemctl reload httpd systemctl restart httpd

# 查看模块 httpd -M | grep rewrite httpd -M | grep ssl

# 错误日志 tail -50 /var/log/httpd/error_log tail -50 /var/log/apache2/error.log

# .htaccess示例 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

# 虚拟主机配置 ServerName 域名 DocumentRoot /var/www/域名 AllowOverride All Require all granted ErrorLog logs/域名-error_log CustomLog logs/域名-access_log common ```

安全配置: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与Apache区别:Nginx事件驱动异步非阻塞,高并发性能好,配置简洁,不支持 .htaccess;Apache进程/线程驱动,稳定,支持 .htaccess和丰富模块,高并发内存占用大。静态资源和高并发选Nginx,需要 .htaccess和复杂模块选Apache,也可以Nginx反代Apache。

华夏名网虚拟主机Web服务器_Apache .htaccess不生效

标签:

更新时间:2026-08-26 20:40:26

上一篇:php网站发布文章提示表单令牌错误_token验证与session

下一篇:华硕电脑实现微信5个微信_多开工具代码_直播专用