I am trying to reverse proxy into a cPanel account by attempting to use the following Nginx configuration (123.123.123.123
is the cPanel IP), but I'm getting an error: ERR_TOO_MANY_REDIRECTS
server {
server_name example.com
access_log /var/log/nginx/reverse-access.log;
error_log /var/log/nginx/reverse-error.log;
location / {
proxy_pass http://123.123.123.123;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name example.com
access_log /var/log/nginx/reverse-access.log;
return 404; # managed by Certbot
}
The following is returned by curl:
curl --head https://example.com/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Mon, 04 Oct 2021 20:59:17 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
expires: Thu, 19 Nov 1981 08:52:00 GMT
cache-control: no-store, no-cache, must-revalidate
pragma: no-cache
x-redirect-by: WordPress
location: https://example.com/
x-litespeed-cache: hit
curl --head http://example.com --resolve example.com:80:123.123.123.123
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Mon, 04 Oct 2021 20:59:33 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://example.com/
The only thing I can find on the topic is: cPanel powered site is not accessible via IP address by my reverse proxy (it gives a 404 error) Could it be the same issue of a header being required?
Loading http://123.123.123.123
does open the site by the way.
Update:
By adding the following to: /etc/hosts
123.123.123.123 example.com www.example.com
and then changing proxy_pass
to:
proxy_pass https://example.com:443;
I now see the following not found error that cPanel returns:
443
(proxy_pass https://123.123.123.123:443
), since I assume you want to proxy an HTTPS site on your cPanel server. Proxying port80
might lead to redirect errors if that's being redirected in the cPanel server (by WordPress for example), which appears is the case based on your curl output since you're being301
redirected to the HTTPS protocol.123.123.123.123 example.com
and then changing the proxy_pass address toproxy_pass https://example.com:443
but now I get the page not found error cPanel gives out i.gyazo.com/a2bfecb59b559a51c6670607858fa959.png443
forproxy_pass
solved the original problem regarding "ERR_TOO_MANY_REDIRECTS". I'm not sure why you modified the hosts file though and didn't just use the IP as in my comment, and then pass the host using proxy_set_header. That would allow Apache in cPanel to direct incoming requests to the correct virtual host.