关于在windows系统下nginx部署静态资源文件时遇到的路径问题

server {
    listen 80;
    server_name localhost;
        access_log  C:/web/access.log;
        error_log   C:/web/error.log;
        location / {
                proxy_pass http://localhost:8081;
        }
        location /static/ {
                root C:/static/;
                autoindex on;
        }

}

这是我的nginx.conf中的一部分信息,我设置了/static/作为我的静态资源库,指定的路径是C:/static ; 

这时候正常来说应该是:

路径:C:/static/1.txt 的文件,我通过 http://localhost/static/1.txt 就可以访问到了,但是事实是我怎样都访问不到,系统会报错,提示我访问的是 C:/static/static/1.txt 文件,一脸懵逼。于是我把nginx.conf里的root路径上调,改成了C:/ ,才能正常使用

server {
    listen 80;
    server_name localhost;
        access_log  C:/web/access.log;
        error_log   C:/web/error.log;
        location / {
                proxy_pass http://localhost:8081;
        }
        location /static/ {
                root C:/;
                autoindex on;
        }

}

这样修改后重启nginx,我通过 http://localhost/static/1.txt 就可以访问到了路径为 C:/static/1.txt 的文件。

甚是奇怪,希望有大神给我解惑,为什么多了一层目录。

发布了20 篇原创文章 · 获赞 8 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/a26637896/article/details/88892535