Intermittent 502 Bad Gateway Errors on Subdomains

Hi. I'm running a web site with a few subdomains and I'm running into a problem where I get intermittent 502 errors when visiting the subdomains.

The web site is running on Apache but the 502 errors are from nginx, which seems odd. The errors are intermittent and seem to occur when visiting the subdomains after a period of inactivity (a few minutes). After reloading the page, the request eventually succeeds and then subsequent requests will work fine and consistently until the subdomain is inactive again for a period of time.

For reference, the domain is:
www.sharedigm.com

The subdomains are:
cloudretrocomputing.sharedigm.com
cloudintosh.sharedigm.com
cloudwinxp.sharedigm.com

The subdomains are accessed through redirects from the domains:
www.cloudretrocomputing.com
www.cloudintosh.com
www.cloudwinxp.com

Thanks in advance for any tips!!

-abe.

7 Replies

p.s. I don't see any errors in the nginx error log.
/var/log/nginx/error.log

Are you using a proxy or a CDN (like Cloudflare)? The 502 could be coming from either one of those.

-- sw

Hi!

I'm not using a CDN. All of the resources and scripts are self-contained. One other thing is that the 502 error lists the nginx version (1.16.1). I checked and that's the same version number as the instance of nginx that's installed on my server. So that makes me think that the error is coming from my Linode web server. The site is served from Apache (httpd), so I don't understand where nginx is involved.

Can you post the apache2(8) configuration for one of the URLs that's causing the 502s…including the piece of config that does the redirect? I'm assuming the configurations for the all the sites are the same.

Also, can you please post an example log entry for an error?

Are you using the apache2(8) module for php (libapache2-mod-php.xx.yy) or are you using php-fpm(8). Do you have any errors associated with these in your php-fpm(8) log?

Did you write the php code or did you use some 3rd party framework/system?

Thanks.

-- sw

Hi Steve from Oregon!

Yes, I am using the Apache2 php module. Here are the vhost definitions for the domain and a subdomain. This includes rewrite rules to redirect http requests to https:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName sharedigm.com
    ServerAlias www.sharedigm.com
    DocumentRoot /var/www/html/sharedigm.com/prod/
    ErrorLog /var/www/html/sharedigm.com/logs/error.log
    CustomLog /var/www/html/sharedigm.com/logs/access.log combined
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =sharedigm.com [OR]
    RewriteCond %{SERVER_NAME} =www.sharedigm.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName cloudintosh.sharedigm.com
    ServerAlias cloudintosh.sharedigm.com
    DocumentRoot /var/www/html/cloudintosh.com/prod
    ErrorLog /var/www/html/cloudintosh.com/logs/error.log
    CustomLog /var/www/html/cloudintosh.com/logs/access.log combined
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =cloudintosh.sharedigm.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

The PHP code is all my own except for the Laravel framework that it is built on top of.

I took a look in the Apache error logs in /var/log/httpd but I didn't see any recent errors listed. I did, however, see some items in the ssl_error_log that look like this:

[Thu Dec 10 05:04:40.732560 2020] [autoindex:error] [pid 2038] [client 184.105.139.69:48516] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

Any idea what this means? Each of these web sites has an index.html file so they all have index pages. They are all single page web apps with an html/javascript front end and a corresponding php/Laravel web services back end.

One other thought… The problem also seems linked perhaps to poor web connectivity. It seems to occur more often when I'm having (or my ISP is having) a bad internet day and requests sometimes time out. On days and times when the connection is good, it seems perhaps to be less of an issue.

Thank you, thank you, thank you.

-abe.

Yes, I am using the Apache2 php module. Here are the vhost definitions for the domain and a subdomain.

I asked that because use of the apache2(8) php module restricts you to mpm_prefork. How big is your Linode?

All your configuration looks OK.

The PHP code is all my own except for the Laravel framework that it is built on top of.

I asked that because sometimes framework developers assume everyone uses the web server they use and hard code things about it into their messages.

I took a look in the Apache error logs in /var/log/httpd but I didn't see any recent errors listed. I did, however, see some items in the ssl_error_log that look like this:

[Thu Dec 10 05:04:40.732560 2020] [autoindex:error] [pid 2038] [client 184.105.139.69:48516] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

Any idea what this means? Each of these web sites has an index.html file so they all have index pages. They are all single page web apps with an html/javascript front end and a corresponding php/Laravel web services back end.

This means that you probably have index.html and index.php in your site directory. apache(8) can't figure out which one to serve by default. This can be easily fixed by inserting the directive:

DirectoryIndex index.html

if you want to serve index.html by default or

DirectoryIndex index.php

if you want to serve index.php by default or

DirectoryIndex index.php index.html

if you want to serve index.php by default and fallback to index.html if it doesn't exist. More here. This directive needs to go into each of your virtual hosts (right after DocumentRoot IMHO).

One other thought… The problem also seems linked perhaps to poor web connectivity. It seems to occur more often when I'm having (or my ISP is having) a bad internet day and requests sometimes time out. On days and times when the connection is good, it seems perhaps to be less of an issue.

This is probably the case… The only thing you can maybe do here is stop using the libapache2-mod-php.xx.yy module and use php-fpm(8) with unix-domain sockets for apache2(8)-to-php IPC. That will allow you free yourself from being restricted to mpm_prefork and use one of the higher performance, multi-threaded MPMs (mpm_worker or mpm_event).

-- sw

Thanks. I added the DirectoryIndex directive and so far it seems happy. I'll keep an eye on it. Much appreciated!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct