配置nginx访问本地静态资源、本地图片、视频。

配置nginx访问本地静态资源、本地图片、视频。

1、进入nginx安装目录
2、打开conf文件夹下的nginx.conf文件,进行配置。

步骤:①打开文件后找到http中的server

②再添加一个server配置,将需要从其他电脑访问的本地路径进行配置。配置内容如下:

复制代码
server {
    listen       8099;								#//监听的端口号
    server_name  localhost;							#//服务ip
    location /source/ {								#//资源访问路径
        alias   D:/kat/gather/sourcePic/source/;	#//访问http://服务ip:8099/source/时会重定向到D:/kat/gather/sourcePic/source/目录下
    }

    location /handelEnd/ {							#//资源访问路径
        alias   D:/kat/gather/sourcePic/source_A/;	#访问http://服务ip:8099/handelEnd/时会重定向到D:/kat/gather/sourcePic/source_A/目录下
    }
    error_page   500 502 503 504  /50x.html;		#错误重定向的页面,这个配不配都行
    location = /50x.html {
    root   html;
    }
}
复制代码
# 完整的nginx.conf配置文件

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;
        location /imgs/ {
            alias   D:/ceshi/;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

    server {
        listen       8099;
        server_name  localhost;
        location /source/ {
            alias   D:/kat/gather/sourcePic/source/;
        }

        location /handelEnd/ {
            alias   D:/kat/gather/sourcePic/source_A/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

}
3、重启nginx服务

步骤:

①在nginx安装目录下进入cmd命令后窗口。

②执行D: ignxgerenxiangmu ginx-1.12.2> nginx.exe -s quit停止nginx服务。(注这个命令是完整有序的停止 nginx,并保存相关信息所以停止是需要数秒的时间。)

③执行D: ignxgerenxiangmu ginx-1.12.2> start nginx启动nginx服务。

4、访问图片验证配置成功

浏览器中访问:http://你自己的ip:8099/source/a40ea9e0b1b560d9c4d5bcf39618b66.jpg

start nginx`启动nginx服务。

4、访问图片验证配置成功

浏览器中访问:http://你自己的ip:8099/source/a40ea9e0b1b560d9c4d5bcf39618b66.jpg

相关推荐
firstacui18 小时前
Docker容器网络管理与容器数据卷管理
运维·docker·容器
XRJ040618xrj18 小时前
Nginx下构建PC站点
服务器·前端·nginx
江畔何人初19 小时前
/etc/profile,.profile,.bashrc三者区分
linux·运维·云原生
会飞的土拨鼠呀19 小时前
Ubuntu系统缺少 iptables 工具
linux·运维·ubuntu
前端玖耀里19 小时前
详细介绍Linux命令dig和nslookup
linux·运维·服务器
星期五不见面19 小时前
jetson naon super使用 sudo /opt/nvidia/jetson-io/jetson-io.py 界面闪退
linux·运维·服务器
FreeBuf_19 小时前
AutoPentestX:面向 Linux 系统的自动化渗透测试工具包
linux·运维·自动化
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.19 小时前
Nginx 平滑升级与回滚超详细指南
运维·nginx
网硕互联的小客服19 小时前
linux服务器忘记远程端口怎么办?如何找回?
linux·运维·服务器
历程里程碑19 小时前
Linux 16 环境变量
linux·运维·服务器·开发语言·数据库·c++·笔记