虚拟主机Nginx root与alias区别_修复实操
商务中国虚拟主机服务器用Nginx或Apache遇到Nginx root与alias区别,先做配置语法检测。Nginx用nginx -t,Apache用apachectl configtest,语法通过再重载。Nginx root与alias区别时80% 是配置语法错或路径错,检测工具能直接指出错误行号。
Apache配置结构:主配置httpd.conf → Include conf.d/*.conf → 虚拟主机VirtualHost → .htaccess(目录级覆盖)。.htaccess需要AllowOverride All才生效,mod_rewrite模块要开启。Apache配置改完systemctl reload httpd,.htaccess改完立即生效不需要重启。
参考(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倍,高并发场景必备。
Nginx与Apache区别:Nginx事件驱动异步非阻塞,高并发性能好,配置简洁,不支持 .htaccess;Apache进程/线程驱动,稳定,支持 .htaccess和丰富模块,高并发内存占用大。静态资源和高并发选Nginx,需要 .htaccess和复杂模块选Apache,也可以Nginx反代Apache。

更新时间:2026-08-31 21:27:23
上一篇:华夏名网虚拟主机404 页路径配置完整教程_Linux 虚拟主机自定义404配置