V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Concise
V2EX  ›  程序员

nginx 反代如何支持原网站的登录 以及部分网站不显示图片问题

  •  
  •   Concise · 2020-01-01 01:03:33 +08:00 · 2263 次点击
    这是一个创建于 1548 天前的主题,其中的信息可能已经有所发展或是发生改变。
    server {
    listen 443 ssl;
    server_name xx;
    ssl_certificate full_chain.pem;
    ssl_certificate_key private.key;
    underscores_in_headers on;
    location / {
    proxy_pass xx;
    proxy_redirect off;
    rewrite /(.*)$ /$1 break;
    proxy_set_header Host $proxy_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 100M;
    client_body_buffer_size 128k;
    proxy_connect_timeout 2;
    proxy_send_timeout 15;
    #proxy_read_timeout 60;
    proxy_buffer_size 128k;
    proxy_buffers 32 32k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
    root /www/wwwroot/default/;
    if (-f $request_filename) {
    expires 1d;
    break;
    }
    }
    location ~ .*\.(js|css)$
    {
    root /www/wwwroot/default/;
    if (-f $request_filename) {
    expires 1d;
    break;
    }
    }


    }

    就照着网上弄来的代码 代理百度的时候图片都正常 就是点登录没反应
    代理 google 和 pixiv 则无法正常显示图片 应该就是规则设置的问题
    希望有经验的能教一下怎么支持登录以及正常显示图片
    5 条回复    2020-01-01 09:50:49 +08:00
    Concise
        1
    Concise  
    OP
       2020-01-01 01:04:24 +08:00
    因为注册还不满一个月不能发带有网址的帖子 就用 xx 替代了
    Concise
        2
    Concise  
    OP
       2020-01-01 01:04:44 +08:00
    Concise
        3
    Concise  
    OP
       2020-01-01 01:14:32 +08:00
    抓包看了一下 好像是因为图片地址在另外一个域名上 所以没能走我的服务器进行传输导致 404 了 应该再添加什么规则解决呢...
    Tink
        4
    Tink  
       2020-01-01 09:03:05 +08:00 via iPhone
    ngxin 反代别折腾登陆了
    artandlol
        5
    artandlol  
       2020-01-01 09:50:49 +08:00 via Android   ❤️ 1
    在 proxy 时去掉 rewrite,不在这里做跳转。
    你的 timeout 值太低,全部做成 1800s,也就是对原网站超时不做处理(记得加单位 s)。
    https 要加 add_header Content-Security-Policy upgrade-insecure-requests;
    端口如果不是 80 和 443,proxy_set_header 这里要设置成$host:$server_port,最好统一这么设置
    补充。对日志文件做下切割,对 http 做跳转 https,用$scheme 去检测
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3392 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:18 · PVG 19:18 · LAX 04:18 · JFK 07:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.