Mobile app version of vmapp.org
Login or Join
Megan663

: Nginx 502 Bad gateway on shared hosting I have a website on a shared hosting provider. Since the very beginning my visitors have randomly got several types of errors, including 502 Bad Gateway

@Megan663

Posted in: #Error #Php #SharedHosting

I have a website on a shared hosting provider. Since the very beginning my visitors have randomly got several types of errors, including 502 Bad Gateway / nginx (blank page with the error text). I have contacted the support several times, and in the end they always claim that the error is in my PHP scripts. I see no errors in PHP logs and my code works perfectly on my home servers.

Other types of errors I have seen:

open_basedir restriction in effect. File(A PHP FILE ON MY SITE) is not
within the allowed path(s): (/home/u514320864:/tmp:/var/tmp:/opt/php-5.3/pear) in ...


Firstly, the user u514320864 is not my username. This string doesn't appear anywhere in my code. Randomly my home directory is not within the allowed paths, until I refresh the page and things start working again.

Then I've also seen a blank page with message No input file specified. That's it, nothing in the error logs.

I have seen the last two errors quite rarely (like a dozen times), but the first one (502) is a pain in the ass. On "bad days" it appears on every 10th page request or so. It always goes back to normal with a page refresh though.

I develop mobile apps, and the 502 error sometimes makes our Android apps nearly unusable (every user action needs some communication between the app and server side).

Is there anything I could do? I have an SSH access to the host server with very limited privileges. I have checked the DNS settings and they seem to be correct.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Megan663

1 Comments

Sorted by latest first Latest Oldest Best

 

@Annie201

Based on the error message alone, I would suggest to ensure all files in your app are within the folder you're allowed to place data in. then if possible, use absolute paths when referencing files.

For example, Assume your site layout is as follows:

In your document root folder you have
Folder named Scripts, and a script named index.php

In the Scripts folder you have
File named 123.php that represents the script you want to load


In this setup, if someone accesses just your domain name, then its likely index.php will load its contents. That file can contain the following contents:

<?php
include "Scripts/123.php";
// rest of startup code goes here
?>


If you can, get the full path info to your document root (I assume here that path is /path/to/document/root), then make your index php file like this:

<?php
include "/path/to/document/root/Scripts/123.php";
// rest of startup code goes here
?>


That way you know you're at least pointing to the correct file. Just going into ssh to your document root and typing pwd and hitting enter should give you the absolute path to your document root.

If you just specify only a file name with no folder information, then php will scan all the predefined include folders (from the php configuration file) (aka "allowed paths") for your script, and some of these folders are likely outside of your user space.

Its possible that the bad gateway can be returned if the file you're requesting begins with an unusual or undefined protocol (like xx://).

My recommendation is to use files and absolute pathnames when referencing other files from within scripts.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme