XanderYe的个人小站

nginx绝对路径和相对路径的问题

1.第一种绝对路径

location /proxy/ {
    proxy_pass http://10.0.0.1:8080/;
}

当访问 http://127.0.0.1/proxy/test.txt 时,实际请求代理服务器的路径为http://10.0.0.1:8080/test.txt

2.第二种相对路径

location /proxy/ {
    proxy_pass http://10.0.0.1:8080;
}

当访问 http://127.0.0.1/proxy/test.txt 时,实际请求代理服务器的路径为http://10.0.0.1:8080/proxy/test.txt

3.第三种

location /proxy/ {
    proxy_pass http://10.0.0.1:8080/blog/;
}

当访问 http://127.0.0.1/proxy/test.txt 时,实际请求代理服务器的路径为http://10.0.0.1:8080/blog/test.txt

4.第四种

location /proxy/ {
    proxy_pass http://10.0.0.1:8080/blog;
}

当访问 http://127.0.0.1/proxy/test.txt 时,实际请求代理服务器的路径为http://10.0.0.1:8080/blogtest.txt

5.root

location /proxy/ {
    root /data/;
}

当访问 http://127.0.0.1/proxy/test.txt 时,实际请求的路径为 /data/proxy/test.txt

6.alias

location /proxy/ {
    alias /data/;
}

alias 正如其名,alias指定的路径是location的别名,不管location的值怎么写,资源的 真实路径都是 alias 指定的路径

当访问 http://127.0.0.1/proxy/test.txt 时,实际请求的路径为 /data/test.txt

赞赏

发表评论

textsms
account_circle
email

XanderYe的个人小站

nginx绝对路径和相对路径的问题
1.第一种绝对路径 location /proxy/ { proxy_pass http://10.0.0.1:8080/; } 当访问 http://127.0.0.1/proxy/test.txt 时,实际请求代理服务器的路径为http://10.0.…
扫描二维码继续阅读
2019-11-26