I have a config file like this;
<VirtualHost *:80>
ServerName example.com
ServerAdmin [email protected]
# Redirect all HTTP traffic to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName example.com
# SSL Configuration
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/fullchain.pem
# Reverse Proxy Settings for WebSocket connections
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /(.*) ws://localhost:5001/$1 [P,L]
# Reverse Proxy Settings for other HTTP/S traffic
ProxyPass /comment/ http://localhost:5000/comment/
ProxyPassReverse /comment/ http://localhost:5000/comment/
ProxyPass /test/ http://localhost:5002/test/
ProxyPassReverse /test/ http://localhost:5002/test/
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /uploads !
ProxyPass / http://localhost:5001/
ProxyPassReverse / http://localhost:5001/
Alias /uploads /var/www/uploads
<Directory /var/www/uploads>
Require all granted
Options FollowSymLinks
AllowOverride None
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
I made settings for ports 5000, 5001 and 5002 in my config file. A Flask API is running in 5000, a .NET API is running in 5001, and in 5002 I am running almost the same .NET API that runs in 5001. My problem is as follows;
When I make a GET request to my API in 5002;
https://example.com/test/getdata
Response;
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>502 Proxy Error</title>
</head>
<body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request
<p>Reason: <strong>Error reading from remote server</strong></p>
</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at example.com Port 443</address>
</body>
</html>
But if I assign the request like this;
https://example.com:5002/getdata
{
"id": 1
}
The problem seems to be proxy related. I’ve tried a lot of things but I’m open to new ideas. Thank you very much in advance.