window 使用nginx搭建静态资源服务器

540 阅读1分钟

1.下载nginx

nginx.org/en/download… 官网下载 nginx

2. 解压打开nginx

打开nginx可能出现的问题:打开nginx出现闪退

  • 出现的原因
    • 80端口被占用
    • nginx 放在含有中文的路径下
  • 端口被占用解决方法

3. 搭建静态资源服务器

打开config 文件夹下的 nginx.conf 加入下面的代码

server {
        listen 9091;
        server_name resouce;
        root D:/nginx/resource;
        autoindex on;
        location / {
            add_header Access-Control-Allow-Origin *;   
        }
        add_header Cache-Control "no-cache, must-revalidate";
    }

重启nginx 打开浏览器输入 http://localhost:9091/ 就可以看到

Snipaste_2022-01-06_11-16-59.png

说明静态资源服务器搭建成功