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.

  • I assume you've seen this question over on StackOverflow: nginx 502 bad gateway? (Seems to be a commonly reported problem?) However, this sounds like a server issue, rather than something you can resolve on a shared host?? What is open_basedir set to (normally)?
    – MrWhite
    Commented Jan 12, 2016 at 9:02
  • Yes, I have seen that post. However, it's not very helpful since I'm able to see some configuration files but unable to modify any of them. open_basedir is set to /home/uXXXXXXXXX:/tmp:/var/tmp:/opt/php-5.5/pear where uXXXXXXXXX is my correct username.
    – Aleksiv95
    Commented Jan 12, 2016 at 10:01
  • I don't think you will be able to solve the issue without cooperation from your hosting company. If you can't get that, I'd say that it is time to look for new web hosting. I've never used web hosting that has problems that bad. Commented Jan 12, 2016 at 14:55
  • Yeah, that's what I thought. It's a shame they won't investigate it any further, they just say "fix your broken PHP script" :D The host company provides a really nice set of features so I'm not very happy to switch but I guess that's the next step.
    – Aleksiv95
    Commented Jan 12, 2016 at 18:23
  • 1
    From looking at that username is your host affiliated with hostinger (hosting24, youhosting reseller, mainhosting)? I only ask because if so i would urge you to backup your files and move else ware. Over the past year and a half hostinger quality has gone down tremendously and there have been all sorts of reports of issues quite similar to what you have posted.
    – Analog
    Commented Mar 20, 2016 at 22:29

1 Answer 1


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:

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:

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.

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.