配置nginx訪問本地靜態(tài)資源,本地圖片,視頻教程
配置nginx訪問本地靜態(tài)資源、本地圖片、視頻
1、進入nginx安裝目錄

2、打開conf文件夾下的nginx.conf文件,進行配置
步驟:
①打開文件后找到http中的server
②再添加一個server配置,將需要從其他電腦訪問的本地路徑進行配置。
配置內容如下:
server {
listen 8099; #//監(jiān)聽的端口號
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命令后窗口。
②執(zhí)行D:\nignx\gerenxiangmu\nginx-1.12.2> nginx.exe -s quit停止nginx服務。(注這個命令是完整有序的停止 nginx,并保存相關信息所以停止是需要數(shù)秒的時間。)
③執(zhí)行D:\nignx\gerenxiangmu\nginx-1.12.2> start nginx啟動nginx服務。
4、訪問圖片驗證配置成功
瀏覽器中訪問:
http://你自己的ip:8099/source/a40ea9e0b1b560d9c4d5bcf39618b66.jpg
start nginx`啟動nginx服務。
4、訪問圖片驗證配置成功
瀏覽器中訪問:
http://你自己的ip:8099/source/a40ea9e0b1b560d9c4d5bcf39618b66.jpg

總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Nginx配置四層、七層網(wǎng)絡代理轉發(fā)的方法示例
nginx作為透明代理可以充分利用其高性能和靈活性來實現(xiàn)網(wǎng)絡流量的轉發(fā)和處理,本文主要介紹了Nginx配置四層、七層網(wǎng)絡代理轉發(fā)的方法示例,具有一定的參考價值,感興趣的可以了解一下2024-03-03
Nginx實現(xiàn)https網(wǎng)站配置代碼實例
這篇文章主要介紹了Nginx實現(xiàn)https網(wǎng)站配置代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-11-11
詳解Linux環(huán)境下使Nginx服務器支持中文url的配置流程
這篇文章主要介紹了Linux環(huán)境下使Nginx服務器支持中文url的配置流程,文中還介紹了一個在Linux下將非UTF-8的文件名轉換為UTF-8編碼,的方法,需要的朋友可以參考下2016-04-04

