zoukankan      html  css  js  c++  java
  • nginx:在server中配置多个location,避免跨域访问


    upstream test {
         server 127.0.0.1:9080 weight=1;     
         #server 192.168.4.68:80 weight=1;
         #ip_hash;                           
     }             
    
    
        server {
             listen       80;
             server_name  jsjnks.test.com;
             charset utf-8;
             location / {
                 proxy_pass http://test;
                 proxy_set_header Host      $host;
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 proxy_redirect  off; 
             }        
             location /public {
                 alias  "D:/app/nginx/html/public";
             }    
             location /jsjnks-static {
                 alias  "D:/app/nginx/html/test-static";
             }            
         }

    public,test-static都是静态资源目录,域名时static.test.com.

    用上面配置后,就避免了JS等静态资源的跨域访问,都处于jsjnks.test.com这一个域名路径之下。

    注意红色部分一定要正确!

  • 相关阅读:
    Xshell 设置右键粘贴功能
    python中dict操作集合
    mac 设置网页字体
    博客收藏
    memcache 安装与简单使用
    mac安装homebrew
    Graphviz下载 使用
    jekyll 与hexo
    js 汉字排序
    初试gem
  • 原文地址:https://www.cnblogs.com/huiy/p/13334958.html
Copyright © 2011-2022 走看看