关于 nginx 反代理谷歌的问题~有人能帮忙回答下吗?

2014-06-24 02:05:50 +08:00
 liuchen9586
想问一下大家,我用我自己服务器搭了个nginx反向了一下谷歌主页,各种功能正常,https也开启了。我现在的情况是,访客访问http是出现nginx欢迎页面,强制在前面加上https才会显示google主页。我想让访客访问http页面就会自动跳转到https页面,请问我该怎么做呢?

反代理谷歌的页面是https://ssl.okami.us 我想让访客访问ssl.okami.us就直接跳转到带https的,请问怎么做?

(楼主语死早,如果有什么地方表达有重复有误的,请不要在意~)
3940 次点击
所在节点    问与答
8 条回复
lazycat
2014-06-24 02:08:14 +08:00
301
sharpnk
2014-06-24 03:36:37 +08:00
你的nginx conf?

没有你的配置文件,我只能靠猜了. 但是我觉得如果你把所有到80口的请求都转到443口应该就可以了.

https://gist.github.com/sharpnk/f5130d68cbc4af0adc43
KokongW
2014-06-24 10:22:16 +08:00
楼主能把nginx conf发出来吗?我也是做了一个反代,但是有些bug,想对照着修改一下。
liuchen9586
2014-06-24 11:33:12 +08:00
@KokongW @sharpnk 我把自己修改过的贴上来了 请看一下

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
rewrite ^(.*url.*) https://ssl.okami.us$1;
index index.html index.htm;
}

server {
listen 443 ssl;
server_name ssl.okami.us;
ssl_certificate /usr/local/ssl/ssl_okami_us.crt;
ssl_certificate_key /usr/local/ssl/ssl.okami.us.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {

proxy_redirect off;
proxy_pass https://www.google.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 https;
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_cookie_domain 'google.com' 'okami.us';
subs_filter 'https://www.google.com' 'https://ssl.okami.us';
subs_filter 'http://www.google.com' 'https://ssl.okami.us';
subs_filter 'href="/' 'href="https://ssl.okami.us/';
subs_filter 'onmousedown' ' ';
}
marklrh
2014-06-24 16:00:06 +08:00
server {
listen 80;
listen 443 default_server ssl;
server_name mmm.com;

ssl_certificate /etc/nginx/ssl/xxx.crt ;
ssl_certificate_key /etc/nginx/ssl/yyy.key ;


if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
}

这样配置可以自动转到https
9hills
2014-06-24 16:37:59 +08:00
lz的反代不错
liuchen9586
2014-06-24 19:36:09 +08:00
@9hills 请私下使用 :)
liuchen9586
2014-06-24 19:36:22 +08:00
@marklrh thanks~

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/119180

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX