2015-08-08 18 views
5

Tôi đang cố đảo ngược proxy trang web của mình và sửa đổi nội dung. Để làm như vậy, tôi biên dịch nginx với sub_filter. Nó bây giờ chấp nhận chỉ thị sub_filter, nhưng nó không hoạt động bằng cách nào đó.http_sub_module/sub_filter của nginx và proxy ngược không hoạt động

server { 
    listen  8080; 
    server_name www.xxx.com; 

    access_log /var/log/nginx/www.goparts.access.log main; 
    error_log /var/log/nginx/www.goparts.error.log; 
    root /usr/share/nginx/html; 
    index index.html index.htm; 

    ## send request back to apache1 ## 
    location/{ 
     sub_filter <title> '<title>test</title>'; 
sub_filter_once on; 


    proxy_pass http://www.google.fr; 
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; 
    proxy_redirect off; 
    proxy_buffering off; 
    proxy_set_header  Host   $host; 
    proxy_set_header  X-Real-IP  $remote_addr; 
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 

    } 
} 

Xin hãy giúp tôi

+0

Tại sao bạn có ý định thay đổi nội dung trong cấu hình Nginx? Bạn có muốn sử dụng Nginx ở chế độ chuyển tiếp proxy không? – Anatoly

+0

Vì tôi dự định thêm đầu trang và chân trang vào trang web theo cách này. Tôi muốn sử dụng nó ở chế độ proxy ngược. – thms0

+0

Tôi thậm chí đã thử Httpsubs và subs_filter, nó cũng không hoạt động. Có ai có ý tưởng không? – thms0

Trả lời

16

Kiểm tra xem nguồn thượng nguồn có gzip bật, nếu vì vậy bạn cần

proxy_set_header Accept-Encoding ""; 

nên toàn bộ điều sẽ là một cái gì đó giống như

location/{ 
    proxy_set_header Accept-Encoding ""; 
    proxy_pass http://upstream.site/; 
    sub_filter_types text/css; 
    sub_filter_once off; 
    sub_filter .upstream.site special.our.domain; 
} 

Kiểm tra các liên kết này

Các vấn đề liên quan