1

We're using Nginx 1.6.2 + Passenger 5.0.6 and have a vhost defined with PHP-FPM which serves a MODx installation. Only one location /sinatraapp serves a Sinatra App using Ruby 2.1.1.

The setup is below and works pretty well but we encountered ONE weird issue. When doing a request WITH a Referer, nginx reponds with 403 Forbidden while the Sinatra App/Passenger sent 302 back (302 Redirect is the correct response in this case!). When doing the Request without a Referer, it works as expected.

Does NOT work:

curl -H "Referer: https://www.example.org" https://example.com/sinatraapp

Does work:

curl -H "Referer: -" https://example.com/sinatraapp

Whereas leaving the Referer-Header completly away also works. The Sinatra-App will 302 the user to a MODx subsite example.com/de/something.

Nginx Config:

server {
    listen [::]:443 ssl spdy ipv6only=on;
    listen 443 ssl spdy;
    server_name www.example.com;

    charset utf-8;

    ssl_certificate /etc/ssl/certs/example_com.crt;
    ssl_certificate_key /etc/ssl/private/example_com.key;
    ssl_trusted_certificate /etc/ssl/certs/example_com_bundle.crt;

    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout  10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_dhparam /etc/ssl/certs/dhparam_2048.pem;
    ssl_prefer_server_ciphers on;
    ssl_stapling on;
    #ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4 valid=600s;
    resolver_timeout 15s;

    # 1-yr HSTS
    add_header Strict-Transport-Security max-age=31536000;

    root /var/www/www-production;
    index index.php;
    passenger_enabled off;

    # Sinatraapp
    location ~ ^/sinatraapp {
        alias /var/www/sinatraapp/current/public$1;
        passenger_base_uri /sintraapp;
        passenger_app_root /var/www/sinatraapp/current;
        passenger_document_root /var/www/sinatraapp/current/public;
        passenger_enabled on;      
    }
    location ~ ^/(otherdir|justanother) {
        return 301 https://subdomain.example.com$request_uri;
    }
    location ~ ^/(de|en)/favicon.ico {
        rewrite ^/(de|en)/favicon.ico$ /favicon.ico last;
    }
    location ~ ^/(de|en)/assets {
        rewrite ^/(de|en)/assets(.*)$ /assets$2 last;
    }
    location ~ ^/(de|en)/ {
        rewrite ^/(de|en)/(.*)$ /index.php?cultureKey=$1&q=$2 last;
    }
    location / {
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1 last;
            }
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5_example_com_https.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_ignore_client_abort on;
        fastcgi_param  SERVER_NAME $http_host;
    }
    location ~ /\.ht {
            deny  all;
    }

    client_max_body_size 20m;

    access_log /var/log/nginx/example_com_https.access.log;
    error_log /var/log/nginx/example_com_https.error.log;
}

I was able to workaround this issue by setting

more_set_input_headers 'Referer: -';

inside the passenger /sinatraapp location but i don't know why this error occurs.

  • An alternative workaround is to add `proxy_set_header Referer "";` to the `location` block. – augurar Sep 04 '15 at 19:59
  • Your nginx configuration doesn't include anything that would reject a connection with a 403 error. Look at your web application. Possibly some misbehaving middleware. – Michael Hampton Nov 19 '20 at 09:12

0 Answers0