最终效果是

  • foo.com/ 展示 bar.com/
  • foo.com/syn/ 展示 ack.com/
  • foo.com/ 中的 ack.com/ 链接替换为 foo.com/syn/

目录

开始

foo.com.conf

server
    {
        listen 80;
        #listen [::]:80;
        server_name foo.com ;
        return 301 https://foo.com$request_uri; # redirect http to https
    }

server
    {
        listen 443 ssl http2;
        #listen [::]:443 ssl http2;
        server_name foo.com ;
        auth_basic "Oops.";
        auth_basic_user_file /path/to/.htpasswd;
        location /
            {
                resolver 1.1.1.1;
                proxy_redirect off;
                proxy_set_header Accept-Encoding "";
                proxy_set_header Host bar.com;
                proxy_set_header X-Real-Ip $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_pass https://bar.com/;
                subs_filter ack.com foo.com/syn;
            }

        location /syn
            {
                resolver 1.1.1.1;
                proxy_redirect off;
                proxy_set_header Host ack.com;
                proxy_set_header X-Real-Ip $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_pass https://ack.com/;
            }

        include /path/to/ssl-params.conf; # ssl config
        access_log  /path/to/access.log;
    }

resolver

proxy_pass 使用域名时,添加 resolver [nameserver]; 防止 nginx 启动时产生 host not found in upstream 错误。

或者,直接查询域名 IP 并替换掉域名。

替换文字或链接

使用 subs_filter (ngx_http_substitutions_filter_module)
sub_filter (ngx_http_sub_module),执行 nginx -V 确保 nginx 安装了模块。

反向代理中使用时请加上 proxy_set_header Accept-Encoding ""; ,否则无法替换。

For safety reasons…

Restricting Access with HTTP Basic Authentication

加上 HTTP 认证。

htpasswd 内容可使用 htpasswd-generator 生成。

auth 写在 location 块内仅对该路径生效,写在 server 块内则对块下所有 location 路径生效。

ssl-params.conf

Cipherli.st - Strong Ciphers for Apache, nginx and Lighttpd

    ssl_certificate /path/to/server.cer;
    ssl_certificate_key /path/to/server.key;
    ssl_session_timeout 10m;
    ssl_protocols TLSv1.3 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:!SM2:!SM3:!SM4';
    ssl_session_cache shared:SSL:10m;
    ssl_dhparam /path/to/dhparam.pem;
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" always; # HSTS
    ssl_session_tickets off;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver_timeout 5s;
    ssl_trusted_certificate /path/to/chain.pem;

结束

前几天去了趟亲戚家,被问到在哪看番和下载,我即答并在他家电脑上输入了那个网址……才发觉那个网站原来是“不存在的”。于是今天稍微整了一下,弄出了个镜像站,可能以后会有用吧。

blog 又有半年多没更了,趁机水一篇续个命

标签: none

添加新评论