Win11 + VMware CentOS8 + Nginx 文件共享服务Wiki(网络部署)

 更新时间:2026年05月07日 09:30:44   作者:Harvy_没救了  
本文介绍了在Windows11宿主机上通过VMware运行CentOS8虚拟机,并部署Nginx搭建内网文件下载服务的全过程,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧

一、项目目标

在 Windows 11 宿主机上,通过 VMware 运行 CentOS 8 虚拟机,将主机文件夹共享给虚拟机;部署 Nginx 搭建内网文件下载服务,实现内网所有设备浏览器在线浏览、下载宿主机共享文件夹内资料。

二、环境信息(脱敏)

组件版本/配置
宿主机Windows 11(内网网段:192.168.3.0/24
虚拟机CentOS 8 最小化安装(无GUI桌面)
虚拟化软件VMware Workstation
共享文件夹名WinShare
服务组件Nginx 静态文件服务
最终网络模式虚拟机网卡 桥接模式

实际以个人设备参数为准

三、部署流程 + 故障问题 + 处理措施

1. CentOS8 联网 DNS 解析故障

问题现象

执行 dnf update -y 报错:
Could not resolve host: mirrors.aliyun.com
无法解析软件源域名,下载软件包失败。

根因

系统默认 DNS 配置异常,无法外网域名解析。

解决措施

  1. 重置并配置公共DNS
echo "" > /etc/resolv.conf
echo "nameserver 223.5.5.5" >> /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
  1. 重启网络并测试连通
systemctl restart NetworkManager
ping www.baidu.com
  1. 网络正常后再执行系统更新
dnf update -y

2. Nginx 安装部署

操作步骤

  1. CentOS8 自带基础源可直接安装 Nginx,无需安装 epel-release
dnf install -y nginx
  1. 设置开机自启并立即启动
systemctl enable nginx
systemctl start nginx
  1. 校验运行状态
systemctl status nginx

正常状态:active (running)

3. 关闭防火墙 & SELinux(内网环境必做)

# 关闭并禁用防火墙
systemctl stop firewalld
systemctl disable firewalld

# 临时关闭SELinux
setenforce 0

# 永久关闭SELinux
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

4. VMware 共享文件夹挂载故障

问题现象

执行 ls /mnt/hgfs/ 无任何输出,看不到 Windows 共享目录。

根因

CentOS8 最小化无GUI,不会自动挂载 VMware 共享目录;且默认挂载目录非空,直接 fstab 挂载会冲突报错。

解决措施

  1. 安装虚拟机工具依赖
dnf install -y open-vm-tools
  1. 确保挂载目录存在
mkdir -p /mnt/hgfs
  1. 手动临时挂载(兼容非空目录)
vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other -o nonempty
  1. 校验是否识别共享目录
ls /mnt/hgfs/

正常输出:WinShare

  1. 配置开机自动挂载
# 清理旧冲突配置
sed -i '/vmhgfs-fuse/d' /etc/fstab
# 写入标准挂载配置
echo ".host:/ /mnt/hgfs fuse.vmhgfs-fuse defaults,allow_other,nonempty 0 0" >> /etc/fstab
# 重载系统配置 + 测试挂载
systemctl daemon-reload
mount -a

5. Nginx 配置文件服务(目录浏览+下载)

操作步骤

  1. 备份原始配置
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
  1. 编辑配置文件
vi /etc/nginx/nginx.conf
  1. 替换完整配置(路径固定指向共享目录)
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    server {
        listen 80;
        server_name _;

        root /mnt/hgfs/WinShare;
        index index.html;

        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;

        location / {
            try_files $uri $uri/ =404;
        }
    }
}
  1. 校验配置语法 + 重启生效
nginx -t
systemctl restart nginx

6. Win11 网络与防火墙配置

  1. 查看宿主机内网网段:使用 ipconfig 获取内网网段 192.168.3.0/24
  2. Windows Defender 防火墙已全局关闭,无需单独放行80端口入站规则。

7. 浏览器访问打不开页面故障

问题现象

Nginx 运行正常、共享目录挂载正常、防火墙全关,但访问宿主机IP无法打开文件页面。

根因

Nginx 部署在虚拟机内,若为NAT模式,直接访问宿主机IP不会自动转发80端口到虚拟机;请求无法抵达Nginx服务。

解决措施(推荐方案)

  1. 关机 CentOS8 虚拟机
  2. VMware 虚拟机设置 → 网络适配器 → 改为 桥接模式
  3. 开机后查看虚拟机内网IP
ip a
  1. 内网设备直接访问 虚拟机同网段IP,即可正常浏览下载。

四、最终实现效果

  1. 只需往 Win11 WinShare 文件夹放入资料,无需配置虚拟机;
  2. 虚拟机开机自动挂载共享目录、Nginx 自启;
  3. 内网手机、电脑、平板同网段下,浏览器访问 虚拟机内网IP,在线浏览文件、点击下载。

五、日常维护说明

  1. 宿主机增删文件,Nginx 实时生效,无需重启服务;
  2. 虚拟机重启无丢失配置:共享自动挂载、Nginx 自动运行;
  3. 新增共享目录只需在VMware添加共享名,修改Nginx root 路径即可。

六、常见问题速查表

问题现象排查处理方向
dnf 无法解析域名配置公共DNS,测试外网ping连通性
/mnt/hgfs 为空用带 nonempty 参数手动挂载,配置fstab开机自挂
页面403/404检查Nginx root路径、共享目录挂载状态
浏览器打不开虚拟机网卡改用桥接模式,访问虚拟机IP而非宿主机IP

到此这篇关于Win11 + VMware CentOS8 + Nginx 文件共享服务Wiki(网络部署)的文章就介绍到这了,更多相关VMware CentOS8 Nginx 文件共享内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

最新评论