V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
nfroot
V2EX  ›  问与答

请教 Nginx 反向代理整站时,如何排除某个文件夹(目录或其他路径)

  •  
  •   nfroot · 2017-12-09 11:25:26 +08:00 · 7427 次点击
    这是一个创建于 2292 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目的:反向代理后,不影响 SSL 证书验证过程。(面板:托塔李天王的粉丝法海的宝塔) test3.baidu.com 为用户访问的域名 m.google.com 为被反代的域名

    试过在反向代理规则的前面设置规则,但是无效

    /www/wwwroot/test3.baidu.com/.well-known 为网站目录下的 let's encrypt 证书验证文件存放文件夹

    server
    {
        listen 80;
        server_name test3.baidu.com;
        index index.php index.html index.htm default.php default.htm default.html;
        root /www/wwwroot/test3.baidu.com;
        
        #SSL-START SSL 相关配置,请勿删除或修改下一行带注释的 404 规则
        #error_page 404/404.html;
        #SSL-END
        
        #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
        error_page 404 /404.html;
        error_page 502 /502.html;
        #ERROR-PAGE-END
        
        #PHP-INFO-START  PHP 引用配置,可以注释或修改
       #试过 location /.well-known 加转义符也不行 location /\.well-known 不知道如何是好。
       location /.well-known {
            root /www/wwwroot/test3.baidu.com/.well-known;
        }
    
    	#PROXY-START
        location / 
        {
            proxy_pass http://m.google.com;
            proxy_set_header Host m.google.com;
            proxy_set_header X-Forwarded-For $remote_addr;
            #proxy_cache cache_one;
            #proxy_cache_key m.google.com$request_uri$is_args$args;
            #proxy_cache_valid 200 304 301 302 1h;
            add_header X-Cache $upstream_cache_status;
            proxy_set_header Accept-Encoding "";
            sub_filter "m.google.com" "test3.baidu.com";
            sub_filter_once off;
            expires 12h;
            add_header Content-Security-Policy "script-src 'self' 'unsafe-inline'";
        }
        
        location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
        { 
            proxy_set_header Host m.google.com;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_pass http://m.google.com;
            proxy_set_header Accept-Encoding "";
            sub_filter "m.google.com" "test3.baidu.com";
            sub_filter_once off;
            add_header Content-Security-Policy "script-src 'self' 'unsafe-inline'";
        }
        #PROXY-END
    
    	include enable-php-71.conf;
        #PHP-INFO-END
        
        #REWRITE-START URL 重写规则引用,修改后将导致面板设置的伪静态规则失效
        include /www/server/panel/vhost/rewrite/test3.baidu.com.conf;
        #REWRITE-END
        
        access_log  /www/wwwlogs/test3.baidu.com.log;
    }
    
    7 条回复    2017-12-11 08:48:09 +08:00
    Nioty
        1
    Nioty  
       2017-12-09 12:56:22 +08:00 via Android
    注意下格式 这样的没法看
    nfroot
        2
    nfroot  
    OP
       2017-12-09 15:26:10 +08:00 via Android
    @Nioty 有缩进啊。。。。
    msg7086
        3
    msg7086  
       2017-12-10 13:24:03 +08:00
    你试过 location /.well-known {} 吗?
    nfroot
        4
    nfroot  
    OP
       2017-12-10 20:04:59 +08:00
    @msg7086 我只试过这 2 个方式
    location /.well-known {
    root /www/wwwroot/test3.baidu.com/.well-known;
    }
    location /\.well-known {
    root /www/wwwroot/test3.baidu.com/.well-known;
    }
    nfroot
        5
    nfroot  
    OP
       2017-12-10 20:07:23 +08:00
    @msg7086 谢谢!真的可以哎!
    msg7086
        6
    msg7086  
       2017-12-11 00:22:43 +08:00
    你 root /www/wwwroot/test3.baidu.com/.well-known 的话,访问 /.well-known 不就变成 /.well-known/.well-known 了吗。
    nfroot
        7
    nfroot  
    OP
       2017-12-11 08:48:09 +08:00
    @msg7086 主要是百度谷歌搜出来的就是我测试过的方法,囧,确实也没想到会这样(目标站 404 页面没返回路径)……谢谢啦!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3199 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:01 · PVG 22:01 · LAX 07:01 · JFK 10:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.