Nginx在linux和windows下代理靜態(tài)文件夾方式
windows下
版本:nginx-1.19.2
nginx-1.19.2\conf\nginx.conf
開發(fā)端口 7766,代理E盤下的 data文件夾;
注意路徑,要用反斜杠
root E:\data
最后重啟nginx即可,進(jìn)入 http:192.168.0.xxx:7766,即可
server {
listen 7766;
server_name 192.168.0.xxx;
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Methods *;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root E:\data;
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

linux下
修改nginx.conf
開發(fā)端口 7766,代理home/mydata 文件夾;
注意路徑
root /home/mydata;
server {
listen 7766;
server_name localhost;
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Methods *;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/mydata;
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
重啟nginx
網(wǎng)上方法很多,但如果你的nginx是編譯安裝(如下),

沒有找到sbin目錄,就需要換方式啟動(dòng)。
重啟方式如下
find / -name nginx 先找目錄

看到sbin位置
/usr/sbin/nginx -s reload
重啟即可;
進(jìn)入 http://xxxxxxx:7766
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解讀nginx -s reload會(huì)產(chǎn)生什么影響
這篇文章主要介紹了nginx -s reload會(huì)產(chǎn)生什么影響,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-07-07
Docker Nginx容器和Tomcat容器實(shí)現(xiàn)負(fù)載均衡與動(dòng)靜分離操作
這篇文章主要介紹了Docker Nginx容器和Tomcat容器實(shí)現(xiàn)負(fù)載均衡與動(dòng)靜分離操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
云服務(wù)器使用寶塔搭建Python環(huán)境,運(yùn)行django程序
本文詳細(xì)講解了在云服務(wù)器使用寶塔搭建Python環(huán)境,運(yùn)行django程序的方法。對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-12-12
Nginx實(shí)現(xiàn)負(fù)載均衡和反向代理的方法
Nginx是由俄羅斯人研發(fā)的,應(yīng)對Rambler的網(wǎng)站,并且2004年發(fā)布的第一個(gè)版本,Nginx功能豐富,可作為HTTP服務(wù)器,也可作為反向代理服務(wù)器,郵件服務(wù)器,本文給大家介紹了Nginx實(shí)現(xiàn)負(fù)載均衡和反向代理的方法,需要的朋友可以參考下2024-02-02
Nginx反向代理重寫URL的實(shí)現(xiàn)方案
nginx服務(wù)器代理前端項(xiàng)目,并且反代后端服務(wù)器,開發(fā)時(shí)使用沒有什么問題,部署后存在同樣請求根地址的情況,但是去調(diào)用后端接口就會(huì)出現(xiàn)報(bào)錯(cuò),最后通過重寫url解決問題,所以本文給大家介紹了Nginx反向代理重寫URL的實(shí)現(xiàn)方案,需要的朋友可以參考下2025-04-04

