【问题标题】:Nginx returning 403 when using Twitter URL shortenerNginx 在使用 Twitter URL 缩短器时返回 403
【发布时间】:2023-03-29 09:20:02
【问题描述】:

直接转到https://example.com 可以正常工作。当您将该链接发送给某人并缩短为https://t.co/fBUFn9ap4e 之类的内容时,他们单击该链接并且URL 更改为https://example.com,但服务器返回403 错误。为什么会这样?

Nginx 配置:

upstream example.com {
    server 127.0.0.1:8000;
    keepalive 8;
}

server {

    listen 0.0.0.0:80;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;

}

server {
    #listen 80;
    listen 443 ssl;
    server_name example.com;
    access_log /var/log/nginx/example.com.log;

    root /var/www/example.com/client/public;

    ssl_certificate /etc/nginx/ssl/my_domain.crt;
    ssl_certificate_key /etc/nginx/ssl/my_domain.key;

    location / {
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://example.com;
        proxy_redirect off;
    }

    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|webp)$ {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
    }

    location ~* \.(?:css|js)$ {
        expires 1y;
        access_log off;
        add_header Cache-Control "public";
    }

    location ~* \.(?:rss|atom)$ {
        expires 1h;
        add_header Cache-Control "public";
    }

    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
        expires -1;
    }

    valid_referers none blocked example.com *.example.com;
    if ($invalid_referer) {
        return 403;
    }

 }

server {

    listen 443 ssl;
    server_name www.example.com;
    return 301 https://example.com$request_uri;

}

【问题讨论】:

  • 您的服务器是否支持 cloudflare 服务计划?
  • 不,只是一个带有 nginx 代理到节点应用程序的数字海洋盒
  • 您可以编辑您的问题并添加 nginx 配置详细信息吗?请不要忘记注释掉合格的名称和 IP 地址...您是使用带 ip:port 的 proxy_pass 还是直接连接到应用程序? (在这里找到:stackoverflow.com/questions/30097334/…
  • 感谢您的帮助,当我检查配置时,我完全错过了用简单的英语说,将 403 返回给未知的推荐人!

标签: twitter nginx dns http-status-code-403 url-shortener


【解决方案1】:

羞愧地拍了拍额头

不敢相信我错过了这个:

valid_referers none blocked example.com *.example.com;
if ($invalid_referer) {
    return 403;
}

哑哑哑哑哑哑。获得更多睡眠。

【讨论】:

  • 简单的解决方案是最好的!
猜你喜欢
  • 2018-04-17
  • 2015-06-08
  • 1970-01-01
  • 2011-10-09
  • 2021-06-27
  • 1970-01-01
  • 2015-10-12
  • 2023-03-28
  • 1970-01-01
相关资源
最近更新 更多