• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved 502 Bad Gateway nginx for html files

AndyM

New Pleskian
I'm using Plesk Onyx with Ubuntu 12.04 (Debian) and I just installed Let's Encrypt SSL certificate for a domain. I applied it under Hosting Settings, and then checked "Permanent SEO-safe 301 redirect from HTTP to HTTPS".
After restarting nginx, it re-directs just fine to https://... now, but there's one problem. All html's lead to "502 Bad Gateway" / "nginx" error. Do I need to somehow allow html file types in a nginx config file? If so, how do I do this?
My level of nginx knowledge is essentially 0, so please don't assume I know anything about file locations. I can tell you php-fpm is running. Thanks kindly for any help!
 
I don't think you have to manually allow html file type in nginx.

Please try this command.

Code:
#plesk repair web example.com

change example.com to your domain name

then,

Code:
#service nginx restart

then,

Code:
#service httpd restart
 
I have the same problem.
At the address giorgio.sommaruga.org I have an old site in HTML and Javascript.
In the original hosting environment it was loaded directly without write index.html.
Here, in Plesk, also writing explicitly the entire URL, the website will not start with a 502 Gateway Error of NGinx.

If in the "Hosting Settings" PHP is disabled, the error is 404 File not found.

In the "DNS Settings" the subdomain is defined with a Record A.

Thanks in advance for your help.
 
Last edited:
AusWeb, thanks for the input. I tried those three commands and on the first one it said: Error messages: 0; Warnings; 0 Errors resolved: 0
Still have
502 Bad Gateway
nginx
for a page https://[mydomain].org/index.htm while https://[mydomain].org/index.php works just fine

Please check whether you have selected "PHP FPM Nginx". In that case Nginx is handling all php-requests, while normal html is handled by Apache.

Then check, whether Apache is running:
# service httpd status

Restart it, if it is not running:
# service httpd restart
 
I wouldn't exactly call that solution. It is more or less avoidance of a solution of the httpd service issue by serving all through Nginx. The httpd service issue still exists, and that Nginx has a problem with the index page is yet another indication that the web server reconfiguration has not been done correctly.

Did you try
# /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
?
 
Oh, man! I didn't see under Plesk -> domain -> Apach & nginx Setings there is an option for
Serve static files directly by nginx
I checked this, then ran /usr/local/psa/admin/sbin/httpdmng --reconfigure-all. Now I get 403 Forbidden / nginx error on html pages. I still don't understand this one, but it's one step closer. Does anyone have a guess? It's not permissions, because under the root of httpsdocs/ I have an index.php and index.htm with identical permissions. The php loads while .htm file doesn't. Hmmm.
 
Hi AndyM,

some standart informations for your notice:

As you can see:
Code:
    location ~ /$ {
        index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;
    }
is the standart configuration to serve existing files. If "index.php"AND "index.htm" are both existent, "index.php" will be used in priority before "index.php".
You are able to change that order at => Home > Subscriptions > YOUR-DOMAIN.COM > Apache & nginx Settings => Option: Index files ( Default / Enter custom value )


Second, pls. be aware that some content uses ".htaccess" - files for apache, which nginx can't read and is therefore not aware of such individual directives and modfications. You have to convert them into NGINX DIRECTIVES if you use the combination apache+nginx. Recommended way to achieve that, is to install the Plesk Extension "htaccess to nginx", which you can find for free at your Extension catalog. After installaling the extension, you have an additional option at the right side of each (sub)domain - specific textbox "Additional nginx directives" called "Show .htaccess converter", where a click opens another textbox, where you may paste the content of the ".htaccess" - file and it will convert it into nginx directives after you choosed the button => "Convert to nginx".


Third, pls. consider to INVESTIGATE issues/errors/problems like "502 Bad Gateway" errors with the help of your log - files. They mostly point you directly to the root cause of the issue. ;)

=> /var/www/vhosts/system/YOUR-DOMAIN.COM/logs

or use the Plesk - Log - component at => Home > Subscriptions > YOUR-DOMAIN.COM > Logs
 
Last edited by a moderator:
Hi AndyM,

some standart informations for your notice:

As you can see:
Code:
    location ~ /$ {
        index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;
    }
is the standart configuration to serve existing files. If "index.php"AND "index.htm" are both existent, "index.php" will be used in priority before "index.php".
You are able to change that order at => Home > Subscriptions > YOUR-DOMAIN.COM > Apache & nginx Settings => Option: Index files ( Default / Enter custom value )


Second, pls. be aware that some content uses ".htaccess" - files for apache, which nginx can't read and is therefore not aware of such individual directives and modfications. You have to convert them into NGINX DIRECTIVES if you use the combination apache+nginx. Recommended way to achieve that, is to install the Plesk Extension "htaccess to nginx", which you can find for free at your Extension catalog. After installaling the extension, you have an additional option at the right side of each (sub)domain - specific textbox "Additional nginx directives" called "Show .htaccess converter", where a click opens another textbox, where you may paste the content of the ".htaccess" - file and it will convert it into nginx directives after you choosed the button => "Convert to nginx".


Third, pls. consider to INVESTIGATE issues/errors/problems like "502 Bad Gateway" errors with the help of your log - files. They mostly point you directly to the root cause of the issue. ;)

=> /var/www/vhosts/system/YOUR-DOMAIN.COM/logs

or use the Plesk - Log - component at => Home > Subscriptions > YOUR-DOMAIN.COM > Logs

I realized the index.htm was redirecting to index.php so that was a bad html file to test. All html in fact works fine now without doing anything.

Thank you so much for these pointers. They are all very helpful and I will retain them moving forward. I did not intend to solve my own problem, but I have to be honest and mark my own reply as the official answer to my original problem. However, these bits of information are just as valuable. You are very kind!
 
Hi AndyM,

is the standart configuration to serve existing files. If "index.php"AND "index.htm" are both existent, "index.php" will be used in priority before "index.php".
You are able to change that order at => Home > Subscriptions > YOUR-DOMAIN.COM > Apache & nginx Settings => Option: Index files ( Default / Enter custom value )

Second, pls. be aware that some content uses ".htaccess" - files for apache, which nginx can't read and is therefore not aware of such individual directives and modfications. You have to convert them into NGINX DIRECTIVES if you use the combination apache+nginx. Recommended way to achieve that, is to install the Plesk Extension "htaccess to nginx", which you can find for free at your Extension catalog. After installaling the extension, you have an additional option at the right side of each (sub)domain - specific textbox "Additional nginx directives" called "Show .htaccess converter", where a click opens another textbox, where you may paste the content of the ".htaccess" - file and it will convert it into nginx directives after you choosed the button => "Convert to nginx".

The converter is not working. Nothing happens when I enter anything such as DirectoryIndex ....
I've spent hours trying to figure out why these lines will not work for Additional nginx directives box:

location / {
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}

Here is the error in Plesk:
Invalid nginx configuration: nginx: [emerg] duplicate location "/" in /var/www/vhosts/system/[mydomain.org]/conf/vhost_nginx.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed

What is the correct syntax for saying I want the index files to be either index.php, index.html, or index.htm? Plesk is supposed to make it easy but it seems like everything involves errors on the front end. I've tried everything I can find. I have no idea what this error means.
 
Hi AndyM,

I already pointed you to the options:
You are able to change that order at => Home > Subscriptions > YOUR-DOMAIN.COM > Apache & nginx Settings => Option: Index files ( Default / Enter custom value )
Just CLICK the radio button "Enter custom value", define your very own, unique options and finalize it with a click on your button "Apply" or "OK" at the bottom of the page. You will see, that your nginx configuration file will then change at "/var/www/vhosts/system/YOUR-DOMAIN.COM/conf". ;)

A second directive with the same location is NOT possible with nginx.
 
Hi UFHH01,
I did not mention in last post that I've already tried everything you wrote. I used the Enter custom value for index files: "index.html index.php index.htm". And then restarted nginx, I also reconfigured web server (../httpdmng --reconfigure-all). Nothing works. I still cannot get the following page to load

mydomain.org/somefolder/index.html

However, it does load a non-index file, for example: mydomain.org/somefolder/test.html

The place you're telling me to change index files is under the "Common Apache Settings". If I have nginx enabled, don't I need to do something special under the nginx section, not Apache? Clearly, the Apache setting isn't helping. I don't see anything special in logs yet either to help.
thanks!
 
Hi AndyM,

unfortunately, the "502 Bad Gateway" issue/error/problem is a very common description and there might be several reasons, why this could happen. Even if you search the forum with the search string "502 Bad Gateway", you will find dozens of threads.

Plesk offers a great KB - article, which summarize quite a lot of root causes and possible solutions/suggestions for these issues/errors/problems. Pls. visit:

 
Back
Top