V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
liuchen9586
V2EX  ›  问与答

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

  •  
  •   liuchen9586 · 2014-06-24 02:05:50 +08:00 · 3928 次点击
    这是一个创建于 3595 天前的主题,其中的信息可能已经有所发展或是发生改变。
    想问一下大家,我用我自己服务器搭了个nginx反向了一下谷歌主页,各种功能正常,https也开启了。我现在的情况是,访客访问http是出现nginx欢迎页面,强制在前面加上https才会显示google主页。我想让访客访问http页面就会自动跳转到https页面,请问我该怎么做呢?

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

    (楼主语死早,如果有什么地方表达有重复有误的,请不要在意~)
    第 1 条附言  ·  2014-06-24 19:41:52 +08:00
    大家要用请低调点……我怕我服务器被认证了 :)

    跳转的问题,我想还是不弄了,80端口正好能迷惑一下人。
    谢谢帮助我的v2exer >_<

    Thanks a lot~
    8 条回复    2014-06-24 19:36:22 +08:00
    lazycat
        1
    lazycat  
       2014-06-24 02:08:14 +08:00 via Android   ❤️ 1
    301
    sharpnk
        2
    sharpnk  
       2014-06-24 03:36:37 +08:00   ❤️ 2
    你的nginx conf?

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

    https://gist.github.com/sharpnk/f5130d68cbc4af0adc43
    KokongW
        3
    KokongW  
       2014-06-24 10:22:16 +08:00
    楼主能把nginx conf发出来吗?我也是做了一个反代,但是有些bug,想对照着修改一下。
    liuchen9586
        4
    liuchen9586  
    OP
       2014-06-24 11:33:12 +08:00   ❤️ 1
    @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
        5
    marklrh  
       2014-06-24 16:00:06 +08:00   ❤️ 1
    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
        6
    9hills  
       2014-06-24 16:37:59 +08:00
    lz的反代不错
    liuchen9586
        7
    liuchen9586  
    OP
       2014-06-24 19:36:09 +08:00
    @9hills 请私下使用 :)
    liuchen9586
        8
    liuchen9586  
    OP
       2014-06-24 19:36:22 +08:00
    @marklrh thanks~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   928 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:51 · PVG 04:51 · LAX 13:51 · JFK 16:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.