nginxparse-platformparse-servernginx-reverse-proxypffile

I can't upload PFFile (image) from Parse Dashboard and I get 404 when I try to access it on browser when my parse server uses https


I have a parse server on Digital Ocean with https using nginx proxy method. My parse server url is like https://my-domain.com/myappname. I have added this link to publicServerURL of my parse server in index.js file to use for mailgun and files.

I also have added this link as serverURL in config.json file of Parse Dashboard. I tried to upload a pffile (image) through Parse Dashboard but it says Unable to connect to Parse API . When I change the serverURL in config.json file, from https://my-domain.com/myappname to http://server-ip:port/parse, it's working without a problem, but I get an error when I try to delete a row from the database (With https this thing works without problem)

my file in /etc/nginx/sites-enabled/my-domain.com is the follow (I also hosting my website in the same server with my parse server):

server {

        root /var/www/my-domain.com/html;
        index index.php index.html index.htm index.nginx-debian.html;
        client_max_body_size 100m;
        server_name my-domain.com www.my-domain.com;


        location / {
               if ($request_uri ~ ^/(.*)\.html$) {
                    return 302 /$1;
                }
               #try_files $uri $uri/ =404;
               try_files $uri $uri.html $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

        location /myparseapp {
                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;
        }


    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/my-domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my-domain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.my-domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = my-domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name my-domain.com www.my-domain.com;
    return 404; # managed by Certbot

}

Also I can't access the uploaded PFFile(image) through web browser. The url https://my-domain.com/myappname/files/11d51c92517ace2d17bc376f2da99a50_default.png says 404 Not Found nginx/1.14.0 (Ubuntu)


Solution

  • Finally I found solution!!!

    I used subdomain.my-domain.com instead of my-domain.com/myapp and in nginx config I removed try_files $uri $uri/ =404; and typed the follow

    location / {
                    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;
            }
    

    You need to have / at the end of proxy_pass for the images to work on your browser.