Reputation: 21
Hi I am trying to get a custom 502 page working on a website and can't seem to get it working.
Basically the way i'm testing it is I'm just stopping uwsgi and accessing the page and every time i get the default nginx 502 page. Can someone please explain to me how to get this working? I've been at this for over a week with 0 success. I have a file named 502.html in public_html and i can access it directly with http://ask.ploy.io/502.html but as soon as i stop uwsgi and try to access the main domain http://ask.ploy.io I get the default 502 page. Here is the vhost config:
### nginx vhost conf for ployio
server {
listen 80;
server_name ask.ploy.io www.ask.ploy.io;
access_log /usr/local/apache/domlogs/ask.ploy.io main;
error_log /home/ployio/access-logs/ask.ploy.io debug;
root /home/ployio/public_html;
index index.html index.htm index.php;
location /502.html {
root /home/ployio/public_html;
}
location ~ /\.ht {
deny all;
}
location / {
error_page 404 403 = @uwsgi;
log_not_found off;
error_page 502 /502.html;
root /home/ployio/public_html;
}
location @uwsgi {
internal;
uwsgi_pass unix:/home/ployio/.uwsgi/uwsgi.sock;
include /usr/local/nginx/conf/uwsgi_params;
}
location ~* ^.*\.php$ {
if (!-f $request_filename) {
return 404;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://204.61.223.114:8888;
}
location /cpanel {
rewrite ^/(.*) https://cpanel.ask.ploy.io:2083/$1 permanent;
}
}
Upvotes: 2
Views: 1747
Reputation: 7841
The main issue is in the location @uwsgi
section.. it never seems to handle the 502 return correctly.. maybe by design?
This is a working config
server {
listen 80;
server_name ask.ploy.io www.ask.ploy.io;
access_log /usr/local/apache/domlogs/ask.ploy.io main;
error_log /home/ployio/access-logs/ask.ploy.io debug;
root /home/ployio/public_html;
index index.html index.htm index.php;
location / {
uwsgi_pass unix:/home/ployio/.uwsgi/uwsgi.sock;
include /usr/local/nginx/conf/uwsgi_params;
}
error_page 502 503 504 @maintenance;
location @maintenance {
root /home/ployio/public_html_502;
rewrite ^(.*)$ /502.html break;
}
}
Make sure you put the 502.html in a new root and reference it there.. ps.. randall sucks
Upvotes: 0
Reputation: 412
If 502 it's the only error code you want to handle with a custom error page, you just need to be specific in the location:
location /502.html {
root /home/ployio/public_html;
}
Your current location is only being matched with the exact "/50x.html" path, which indeed does not exists in your server: http://ask.ploy.io/50x.html
It's also possible using nginx variables ($uri or something similar) to redirect all 50x errors to that root directory, but for your needs this should be enough.
Upvotes: 0