Centos 6 下配置nginx 反向代理Google

来源:互联网 发布:学java跟不上 编辑:程序博客网 时间:2024/05/22 12:07
  • 需要条件
  • 一个墙外的VPS
    对VPS的要求不高,搬瓦工128m内存的小机,搭建及使用均毫无压力。

  • 一个域名
    网上有很多地方可以申请免费的域名,比如Freenom,可以免费申请.tk、.ml、.cf、.ga等后缀的顶级域名,最长一年免费,到期可以免费续期。

     

     

    1.在国外vps 安装必须的扩展包

    yum -y install libxml2-devel libxslt-devel pcre-devel gd-devel GeoIP-devel

    为了在反代时,更好的替换原网页中的信息,需要在编译时增加一个第三方模块:substitutions 扩展
    下载 substitutions 的源码

    1
    # git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

    2. 下载Nginx源码

       

        找一个目录放源码,在这个目录里下载对应版本的Nginx源码并解压:

    12
    # wget http://nginx.org/download/nginx-1.9.3.tar.gz# tar -zxvf nginx-1.9.3.tar.gz

    3. 编译源码

    cd nginx-1.9.3./configure  --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=../ngx_http_substitutions_filter_module


     

    4. 配置nginx.conf ,增加一下server配置信息, 注意<example.com> 需要替换成自己的域名

    upstream www.google.com {    server 172.217.4.132:443 weight=1;    server 172.217.0.4:443 weight=1;    server 172.217.1.36:443 weight=1;    server 216.58.193.196:443 weight=1;    server 216.58.216.4:443 weight=1;    server 216.58.216.36:443 weight=1;    server 216.58.219.36:443 weight=1;    server 74.125.25.99:443 weight=1;    server 74.125.25.103:443 weight=1;    server 74.125.25.104:443 weight=1;    server 74.125.25.105:443 weight=1;    server 74.125.25.106:443 weight=1;    server 74.125.25.147:443 weight=1;}# 这里将http的访问强制跳转到https,<example.com>改为自己的域名。  server {     listen       80;    server_name  <example.com>;    # http to https    location / {     proxy_redirect off;     proxy_cookie_domain google.com <example.com>;     proxy_pass https://www.google.com;     proxy_connect_timeout 60s;     proxy_read_timeout 5400s;     proxy_send_timeout 5400s;     proxy_set_header Host "www.google.com";     proxy_set_header User-Agent $http_user_agent;     proxy_set_header Referer https://www.google.com;     proxy_set_header Accept-Encoding "";     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 https;     proxy_set_header Accept-Language "zh-CN";     proxy_set_header Cookie "PREF=ID=047808f19f6de346:U=0f62f33dd8549d11:FF=2:LD=en-US:NW=1:TM=1325338577:LM=1332142444:GM=1:SG=2:S=rE0SyJh2W1IQ-Maw";     subs_filter https://www.google.com.hk <example.com>;     subs_filter https://www.google.com <example.com>;     sub_filter_once off;  }}


     

     

    为了避免被墙,建议申请免费的startssl 访问

     

  • 0 0
    原创粉丝点击