香菊网

幻雨焉缘

坚持比方法更重要 🥗
😃

nginx的 location 配置问题

香菊网 发表于: 2019-03-20 分类: nginx  nodeJs  js部分  服务器serve  

 

大家都知道Nginx是网站配置中最灵活的部分,也是一般网站中必不可少的利器。

nginx 的路由分配, 都是Location。Location支持正则表达式匹配,也支持条件匹配,用户可以通过location指令实现Nginx对动丶静态网页的过滤处理

location [ = | ~ | ~* | ^~ ] uri { ... }
location @name { ... }

下面说一下nginx的 location配置的问题

root 目录配置

location /proxy {

    root   /home/html;

    index  index.html index.htm;

    deny all;

}

以前一直以为指的是/home/html 目录下的 index.html

应该是/home/html/proxy 目录下的 index.html

解决办法就是 root 目录后面加上"/"   即  root /home/html/ 

alias 虚拟目录配置

location /proxy {

    alias   /home/html;

}

alias  指定的目录是准确的,  即location匹配访问的path目录下的文件直接是在alias目录下查找的;

使用alias标签的目录块中不能使用rewrite的break(具体原因不明);另外,alias指定的目录后面必须要加上"/"符号

 

最后

root目录配置中,location匹配的path目录后面带不带"/",都不会影响访问。

alias中 location匹配的path目录后面加上"/",那么访问的url地址中这个path目录必须要加上"/",访问时它不会自动加上"/"。如果不加上"/",访问就会失败!

标签: nginxnodeJsjs部分服务器serve
Copyright © 2019 幻雨焉缘博客 | 浙ICP备19001843号-1
----------------------------------
种一棵树,最好的培养时间是十年前,其次是现在 加油  (ง •_•)ง。        ──── 前端攻城狮