当前位置: 代码网 > 服务器>服务器>Linux > Nginx在linux和windows下代理静态文件夹方式

Nginx在linux和windows下代理静态文件夹方式

2025年11月06日 Linux 我要评论
windows下版本:nginx-1.19.2nginx-1.19.2\conf\nginx.conf开发端口 7766,代理e盘下的 data文件夹;注意路径,要用反斜杠root e:\data最后

windows下

版本:nginx-1.19.2

nginx-1.19.2\conf\nginx.conf

开发端口 7766,代理e盘下的 data文件夹;

注意路径,要用反斜杠

root e:\data

最后重启nginx即可,进入 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

开发端口 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

网上方法很多,但如果你的nginx是编译安装(如下),

没有找到sbin目录,就需要换方式启动。

重启方式如下

find / -name nginx 先找目录

看到sbin位置 

/usr/sbin/nginx -s reload

重启即可;

进入 http://xxxxxxx:7766

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com