使用ngnix搭建静态资源服务器
通过在地址栏输入ip+port的方式来完成目录的映射
nginx下载地址
下载地址
我使用的是:nginx1.16.0
下载后解压
搭建流程
这里以我电脑的D盘下面的abc和boot文件为例,abc文件夹是一个静态页面,boot文件夹是一个文件
- 1、配置conf文件
在解压后的文件夹中打开conf/nginx.conf文件 - 如果nginx的:location /{} 下面没有其他的配置
server {
listen 8888;#访问的端口号
server_name localhost;#访问的ip
location / {
root D:/;#在location /下面配置的话,是将D盘中的所有文件夹作为了静态资源服务器
autoindex on;#打开目录浏览功能
}
}
- 如果nginx的:location /{} 下面有其他配置
server {
listen 8888;
server_name localhost;
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost:8080/123/;
}
location /abc/ {#路径必须为改文件下面有的文件名
root D:/;
autoindex on;
}
location /boot/ {
root D:/;
autoindex on;
}
}
配置成功保存后
在压缩文件下面双击启动nginx.exe
启动后查看logs文件下面是否有nginx.pid文件,如果有说明启动成功,如果没有点击error.log文件查看失败原因
运行结果
-
在网页中访问localhost:8888/abc和localhost:8888/boot结果如下
-
abc静态资源文件夹
-
boot文件夹下