配置nginx訪問本地靜態(tài)資源,本地圖片,視頻教程
更新時間:2025年01月26日 10:49:37 作者:間行字里.
文章介紹了如何配置Nginx以訪問本地靜態(tài)資源、圖片和視頻,首先,進入Nginx安裝目錄并打開`nginx.conf`文件,添加一個新的`server`配置來指定本地路徑,然后,通過命令行重啟Nginx服務以應用更改,最后,通過瀏覽器訪問配置的圖片路徑來驗證配置是否成功
配置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

總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
詳解nginx前端根據(jù)$remote_addr分發(fā)方法
這篇文章主要介紹了詳解nginx前端根據(jù)$remote_addr分發(fā)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11

