nginx 反向代理google
2018-12-11 本文已影响0人
桐间纱路
利用nginx反向代理做一个谷歌镜像,实现谷歌访问。
准备:
一个可以解析的域名。
一台可以访问goole的服务器,并配置nginx,开启ssl。具体方法见:
配置免费ssl证书LetEncrypt,开启全民https时代
nginx配置
在http下添加
server {
listen 80;
server_name 127.0.0.1;
location / {
rewrite ^(.*)$ https://www.example.com$1 permanent; #重写为https
}
}
server {
listen 443 ssl;
server_name 127.0.0.1;
ssl_certificate /usr/local/nginx/conf/www.example.com.cer;
ssl_certificate_key /usr/local/nginx/conf/www.example.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
underscores_in_headers on;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
location / {
proxy_redirect off;
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_redirect http://www.google.com/ /;
proxy_cookie_domain google.com guance.com;
proxy_set_header Accept-Encoding "";
proxy_set_header User-Agent $http_user_agent;
proxy_set_header Accept-Language "zh-CN";
proxy_set_header Cookie "PREF=ID=047808f19f6de346:U=0f62f33dd8549d11:FF=2:LD=zh-CN:NW=1:TM=1325338577:LM=1332142444:GM=1:SG=2:S=rE0SyJh2W1IQ-Maw";
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
# note, there is not SSL here! plain HTTP is used
proxy_pass https://www.google.com;
sub_filter www.google.com www.example.com;
sub_filter_once off;
}
}