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

2017-12-09 11:25:26 +08:00
 nfroot

目的:反向代理后,不影响 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;
}
7449 次点击
所在节点    问与答
7 条回复
Nioty
2017-12-09 12:56:22 +08:00
注意下格式 这样的没法看
nfroot
2017-12-09 15:26:10 +08:00
@Nioty 有缩进啊。。。。
msg7086
2017-12-10 13:24:03 +08:00
你试过 location /.well-known {} 吗?
nfroot
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
2017-12-10 20:07:23 +08:00
@msg7086 谢谢!真的可以哎!
msg7086
2017-12-11 00:22:43 +08:00
你 root /www/wwwroot/test3.baidu.com/.well-known 的话,访问 /.well-known 不就变成 /.well-known/.well-known 了吗。
nfroot
2017-12-11 08:48:09 +08:00
@msg7086 主要是百度谷歌搜出来的就是我测试过的方法,囧,确实也没想到会这样(目标站 404 页面没返回路径)……谢谢啦!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/413285

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX