• nginx 静态目录配置规则


    1、子目录匹配 
    如下配置 

    location / {  
        root /data/www;  
    }  
    

      访问http://127.0.0.1/时,配匹配/data/www 
    访问http://127.0.0.1/images时,配匹配/data/www/images 
    访问http://127.0.0.1/images/1.jpg时,配匹配/data/www/images/1.jpg 
    也就是说,地址栏里"/"后的路径是直接匹配目录data/www/下的路径 

    location /images/ {  
        root /data/www;  
    }
    

      访问http://127.0.0.1/images时,配匹配/data/www/images 
    也就是说,地址栏里/images,直接匹配了/data/www的子目录. 
    经常出问题的是,location里的url随意配了一个名字,如/xxx,但是对应的/data/www目录 
    下并没有该/data/www/xxx子目录,一访问就404
     

    2、重复路径匹配规则 

    server {  
        location / {  
            root /data/www;  
        }  
      
        location /images/ {  
            root /data;  
        }  
    }  
    

      访问URL http://localhost/images/example.png,将会匹配第二个/images/规则, 
    虽然也可以匹配location /规则,但nginx默认会选择最长前缀去匹配当前URL,也就是 
    第二个配置会生效,访问/data/images/目录,而不是/data/www/images/目录 

     server {
            listen       8888;
            server_name  localhost;
    	
    	    
    		
            location / {
              root E:/nginx-1.13.6/html/dist;
    		  try_files $uri $uri/ /index.html;
    		  index  index.html index.htm;		 
            }
    		
    		location /server/ {
    		  proxy_pass http://xxxxxxx:8080/;
            }
    }

      

  • 相关阅读:
    JavaScript实现文本框和密码框placeholder效果(兼容ie8)
    11.24 模拟赛题解
    一句话题解集——口胡万岁
    uTools-插件化定制属于自己的工具集[免费]
    tree
    braintree 支付
    Shopify 接口调用
    TcPlayer腾讯播放器
    微信支付(WeixinJSBridge.invoke、wx.chooseWXPay)
    图片上传(二进制文件流)
  • 原文地址:https://www.cnblogs.com/caonima-666/p/7659864.html
Copyright © 2020-2023  润新知