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)文章
如何利用map實(shí)現(xiàn)Nginx允許多個(gè)域名跨域
這篇文章主要給大家介紹了關(guān)于如何利用map實(shí)現(xiàn)Nginx允許多個(gè)域名跨域的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
nginx隱藏響應(yīng)頭server信息和版本號信息的操作方法
文章介紹了兩種隱藏或修改Nginx響應(yīng)頭中server信息的方法:一種是通過修改配置文件全局段添加`server_tokens off`,另一種是重新編譯Nginx并修改Banner信息,兩種方法分別適用于傳統(tǒng)部署和需要更靈活自定義的情況,需要的朋友可以參考下2025-02-02
Nginx報(bào)403 forbidden錯(cuò)誤 (13: Permission denied)的解決辦法
這篇文章主要介紹了Nginx報(bào)403 forbidden錯(cuò)誤 (13: Permission denied)的解決辦法,引起nginx 403 forbidden通常是三種情況:一是缺少索引文件,二是權(quán)限問題,三是SELinux狀態(tài)。具體內(nèi)容詳情大家可以參考下本文2017-01-01
Nginx 過濾靜態(tài)資源文件的訪問日志的實(shí)現(xiàn)
這篇文章主要介紹了Nginx 過濾靜態(tài)資源文件的訪問日志的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
nginx支持帶下劃線的header實(shí)現(xiàn)
如果header name中包含下劃線,則忽略掉,本文主要介紹了nginx支持帶下劃線的header實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-08-08
Nginx與Lua灰度發(fā)布的實(shí)現(xiàn)
這篇文章主要介紹了Nginx與Lua灰度發(fā)布的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03

