日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Nginx反向代理 對響應網頁中的字符串進行替換設置

作者:狂野小青年 更新時間: 2022-05-12 編程語言
server {
        listen       80;
        server_name  mikecrm.xianzhixiong.com;

        # 上傳文件大小限制
        client_max_body_size 20M;
        # 設置為on表示啟動高效傳輸文件的模式
        sendfile on;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass   http://mikecrm.com;
            proxy_set_header Host mikecrm.com;
            proxy_set_header Referer http://mikecrm.com;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            #proxy_request_buffering off;
            proxy_set_header Accept-Encoding "";
            sub_filter_types *;
            sub_filter_once off;
            #sub_filter_last_modified on;
            sub_filter 'cdnq2.mikecrm.com' 'mikecrm.xianzhixiong.com';
            sub_filter 'cdnq3.mikecrm.com' 'mikecrm.xianzhixiong.com';
            sub_filter 'https://cdnq2plt.mikecrm.com' 'http://mikecrm.xianzhixiong.com';
            sub_filter 'https://cdnq3plt.mikecrm.com' 'http://mikecrm.xianzhixiong.com';
            sub_filter 'http://dlcn.mikecrm.com' '';
            sub_filter 'http://mikecrm.com' '';
            sub_filter 'https://mikecrm.com' '';
            sub_filter 'www.mikecrm.com' 'mikecrm.xianzhixiong.com';
            #sub_filter '.mikecrm.com' 'mikecrm.xianzhixiong.com';
            #sub_filter 'mikecrm.com' 'mikecrm.xianzhixiong.com';
        }
        #location ~ \.php$ {
           # proxy_pass   https://real.mikecrm.com;
        #}
        #location ~ /plt.js$ {
           # proxy_pass   https://cdnq3plt.mikecrm.com;
        #}

}

參數解釋

注意只有在新版本nginx中才支持多sub_filter.

proxy_set_header Accept-Encoding ""; ?

設置這個得原因是:告訴后端不要進行gzip壓縮. ?如果是gzip壓縮流, 那么我們就沒法進行替換了.

sub_filter_types *; ?

對所有請求響應類型都做sub_filter指定的替換.

sub_filter_once off;

sub_filter會執行多次而不是一次. 效果類似于java中的string.replaceAll而不是replace.

sub_filter 'str1'? 'str2';

替換字符串,str1是搜索的字符串,str2是最終被替換成的字符串

原文鏈接:https://wanzhou.blog.csdn.net/article/details/124710838

欄目分類
最近更新