1

I am migrating parse-server to a DigitalOcean Ubuntu droplet based on this documentation:

https://www.digitalocean.com/community/tutorials/how-to-migrate-a-parse-app-to-parse-server-on-ubuntu-14-04

I'm having an issue with nginx proxying (https) requests to parse-server.

If I open port 1337 on my droplet and configure Parse http requests to go directly to parse-server (http://example.com:1337/parse), this all works as expected.

If I configure Parse http requests to go to https://example.com/parse, nginx fails to proxy the request to parse-server.

nginx returns a 404 (which is suspiciously what the / location will do).

The Let's Encrypt SSL cert seems to be working as expected, as I can serve static content (http requests are redirected from 80 to 443 via 301 status).

My nginx default configuration looks like this:

# HTTP - redirect all requests to HTTPS
server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    return 301 https://$host$request_uri;
}

# HTTPS - serve HTML from /usr/share/nginx/html, proxy requests to /parse/
# through to Parse Server
server {
    listen 443;
    server_name example.com;

    root /usr/share/nginx/html;
    index index.html index.htm;

    ssl on;
    # Use certificate and key provided by Let's Encrypt:
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    # Pass requests for /parse/ to Parse Server instance at localhost:1337
    location /parse/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://localhost:1337/;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_redirect off;
    }

    location / {
            try_files $uri $uri/ =404;
    }
}

This is a typical line from nginx access.log:

xxx.xxx.xxx.xxx - - [20/Mar/2016:18:54:53 -0400] "PUT /parse/classes/_User/xxxxxxxxxx HTTP/1.1" 404 68 "-" ...

Is there any way to turn more verbose debugging on so I can tell why the match is failing?

Thanks, peter

Solution (see below) Note the addition of /parse/ on the proxy_pass configuration

  location /parse/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://localhost:1337/parse/;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_redirect off;
    }

1 Answer 1

1

Your configuration does not proxy https://example.com/parse, it proxies https://example.com/parse/. The former URI is processed by the location / block.

Also, the URI https://example.com/parse/ is sent upstream to http://example.com:1337/ rather than http://example.com:1337/parse.

If you need to transparently proxy URIs without a trailing /, use:

location /parse {
    proxy_pass http://localhost:1337;
    ...
}

Notice that two trailing /s have been removed. See this document for details.

1
  • Thank you very much @Richard. The solution for me was to leave the location as /parse/, but change the proxy_pass URL by adding /parse/ to the end. See solution update above.
    – psparago
    Commented Mar 21, 2016 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.